尽管拥有正确的NuGet软件包,为什么我仍需要在计算机上安装MySQL连接器? [英] Why do I still need the MySQL Connector installed on the computer despite having the proper NuGet packages?

查看:44
本文介绍了尽管拥有正确的NuGet软件包,为什么我仍需要在计算机上安装MySQL连接器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用MariaDB和Entity Framework 6的C#ASP.NET MVC项目.

这个项目是在Visual Studio 2017中完成的,我花了很长时间仔细检查我是否以NuGet包的形式添加了正确的MySQL连接器的程序集引用,如 MySQL Connector/NET 8.0 ,然后就可以了.除了NuGet所做的更改之外,没有对web.config文件进行任何更改.

我检查了安装程序放置在%ProgramFiles%\MySql\Connector下的程序集,它们与NuGet提取的程序集完全相同.哎呀,我什至删除了整个文件夹,但仍然可以使用.

有什么作用? NuGet软件包是否缺少应执行的某些步骤?

我怀疑Connector/NET 8.0安装程序会修改您的C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config文件,该文件由计算机上的所有.NET应用程序共享.不幸的是,这是计算机上的本地更改,这意味着您的应用程序在部署时可能无法正常运行.

解决方案是将MySql.Data添加到您的app.config(或Web.config)文件中.我不确定NuGet软件包是否旨在自动执行此操作.

每个 Oracle文档,将此信息添加到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>

I've got a C# ASP.NET MVC project using MariaDB with Entity Framework 6.

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:

The ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is either not registered in the machine or application config file.

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.

I checked the assemblies placed under %ProgramFiles%\MySql\Connector by the installer, and they are bit-identical to those pulled by NuGet. Heck, I even deleted the entire folder, and it still worked.

What gives? Are the NuGet packages missing some step they should perform?

解决方案

I suspect that the Connector/NET 8.0 installer modifies your C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.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.

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.

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连接器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆