首页 > 解决方案 > 在 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包吗?

标签: c#asp.netmysql-connectormysqlconnection

解决方案


该类MySqlconnection在命名空间中定义MySqlConnector。您必须在 Startup 类的顶部添加以下 using 语句:

using MySqlConnector;

推荐阅读