c# - 在 ASP.NET 中找不到“'MySqlConnection'”
问题描述
我目前正在使用这篇文章来尝试将我的 ASP.NET Core 项目连接到我的 MySql 数据库,并按照它的说明安装了 NuGet 包“MySqlConnector”。然后文章说要将此行添加到 Startup.cs 中的“ConfigureServices”函数中。
services.AddTransient<MySqlConnection>(_ => new MySqlConnection(Configuration["ConnectionStrings:Default"]));
但是“MySqlConnection”是红色的,悬停在它上面会显示以下错误:
CS0246: The type or namespace "MySqlConnection" could not be found (are you missing a using directive or an assembly reference?)
有什么我想念的吗?文章中有错字,我应该安装 MySql Connection包吗?
解决方案
该类MySqlconnection
在命名空间中定义MySqlConnector
。您必须在 Startup 类的顶部添加以下 using 语句:
using MySqlConnector;
推荐阅读
- vaadin - Vaadin-10/12 网格组件渲染器性能问题
- visual-studio - 如何在 GitHub 存储库中包含没有大 .vs 文件夹的项目属性?
- unity3d - 多久调用一次 OnTriggerEnter2D?
- arrays - 如何在 VBA 中重新保存锯齿状数组(数组中的数组)?
- sql - How to store address in database
- java - 安卓。遍历父回收器时嵌套的recyclerview自行滚动
- ssl - 是否可以使用 Telegraf 配置安全(SSL)kafka?
- php - get data of rows that are not set as foreign key in Laravel
- php - 将单个 Laravel 通知标记为已读
- angular - Angular Material Sorting a number assending doesn't work