问题描述
我有一个使用 MariaDB 和 Entity Framework 6 的 C# ASP.NET MVC 项目.
I've got a C# ASP.NET MVC project using MariaDB with Entity Framework 6.
这个项目是在 Visual Studio 2017 中制作的,我花了很长时间仔细检查是否以 NuGet 包的形式添加了正确的 MySQL 连接器的程序集引用 MySql.Data 8.0.13 和 MySql.Data.EntityFramework 8.0.13 (均由Oracle官方发布),因为我在调试时浏览视图时遇到以下错误:
This project is made in Visual Studio 2017 and it took me some long hours double-checking whether I had the proper MySQL connector's assembly references added as they should, in the form of NuGet packages MySql.Data 8.0.13 and MySql.Data.EntityFramework 8.0.13 (both oficially published by Oracle), because I was getting the following error when browsing Views while debugging:
具有不变名称MySql.Data.MySqlClient"的 ADO.NET 提供程序未在机器或应用程序配置文件中注册.
The ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is either not registered in the machine or application config file.
直到我放弃它并尝试安装 MySQL Connector/NET 8.0,然后它工作.web.config
文件除了由 NuGet 执行的更改之外,没有进行任何更改.
Until I gave up on it and tried installing the MySQL Connector/NET 8.0, after which it worked. No changes made to the web.config
file other than those performed by NuGet.
我检查了安装程序放置在 %ProgramFiles%MySqlConnector
下的程序集,它们与 NuGet 拉取的程序集有点相同.哎呀,我什至删除了整个文件夹,它仍然有效.
I checked the assemblies placed under %ProgramFiles%MySqlConnector
by the installer, and they are bit-identical to those pulled by NuGet. Heck, I even deleted the entire folder, and it still worked.
什么给了?NuGet 包是否缺少它们应该执行的某些步骤?
What gives? Are the NuGet packages missing some step they should perform?
推荐答案
我怀疑 Connector/NET 8.0 安装程序修改了您的 C:WindowsMicrosoft.NETFramework64v4.0.30319configmachine.config
文件,该文件由机器上的所有 .NET 应用程序共享.不幸的是,这是您机器上的本地更改,这意味着您的应用程序在部署时可能无法正常工作.
I suspect that the Connector/NET 8.0 installer modifies your C:WindowsMicrosoft.NETFramework64v4.0.30319configmachine.config
file, which is shared by all .NET applications on the machine. Unfortunately, this is a local change on your machine, which means that your application may not work properly when deployed.
解决方案是将 MySql.Data 添加到您的 app.config
(或 Web.config
)文件中.我不确定 NuGet 包是否设计为自动执行此操作.
The solution is to add MySql.Data to your app.config
(or Web.config
) file. I'm not sure if the NuGet packages are designed to do this automatically or not.
根据 Oracle 文档,将此信息添加到 app.config
:
Per the Oracle docs, add this information to app.config
:
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=8.0.13.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
这篇关于尽管有正确的 NuGet 包,为什么我仍需要在计算机上安装 MySQL 连接器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!