c# - ASP.NET Core 项目中的 MySql 连接字符串错误

标签 c# mysql asp.net-core-mvc connection-string

我正在构建我的第一个 ASP.NET Core Web 应用程序,并为其使用 MySQL 数据库。 使用 EF Core Power Tools 导入 DB-Context 后,我​​将连接字符串保存在 appsettings.json 文件中。

然后我尝试加载其中一个实体类的索引 View ,但我不断收到以下错误:

ArgumentException: Keyword not supported: 'allowuservariables'.

Exception Stack Trace

我尝试将“allowuservariables=true”从连接字符串中抛出,但随后收到此错误消息:

SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

连接字符串:“server=localhost;user id=root;database=dbname;allowuservariables=True;password=password;persistsecurityinfo=True”

连接字符串有问题还是我缺少识别“allowuservariables”的扩展名?

最佳答案

该代码尝试使用 SqlConnection 连接到 MySQL 数据库,但这不起作用。

确保您在 Startup 的 ConfigureServices 中调用了 UseMySql而不是 UseSqlServer .cs 文件,如 documented here .

关于c# - ASP.NET Core 项目中的 MySql 连接字符串错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65751885/

相关文章:

c# - 模拟的 SignInManager 未按预期工作

c# - 当用鼠标双击时 - 通过哪个按钮发现

c# - 如何防止匿名用户使用表单例份验证访问文件?

php - 使用日期函数搜索内容

mysql - 如何对一年内每月基数表中的值进行分类

mysql - 在mysql中添加公式

visual-studio-2015 - 如何使用project.json引用另一个文件夹中的本地csproj?

c# - 同一台服务器上的 WCF 服务之间的响应缓慢

c# - 使用动态变量解析 JSON block

c# - 如何: Parameter binding from multiple sources