连接MySQL数据库得到错误“Unable to find the requested .Net Framework Data Provider”

 

Each .NET Framework data provider that supports a factory-based class registers configuration information in the DbProviderFactories section of the machine.config file on the local computer. The following configuration file fragment shows the syntax and format for System.Data.SqlClient.

<system.data>
  <DbProviderFactories>
    <add name="SqlClient Data Provider"
     invariant="System.Data.SqlClient" 
     description=".Net Framework Data Provider for SqlServer" 
     type="System.Data.SqlClient.SqlClientFactory, System.Data, 
     Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    />
  </DbProviderFactories>
</system.data>

The invariant attribute identifies the underlying data provider. This three-part naming syntax is also used when creating a new factory and for identifying the provider in an application configuration file so that the provider name, along with its associated connection string, can be retrieved at run time.

 

我下载MySQL连接器/净6.7.4Visual Studio 1.0.2 MySQL随后,然后这些指令测试:

  1. 创建一个连接到现有的MySQL数据库。
  2. 创建一个控制台应用程序。
  3. 添加麻烦。网络实体数据模型从现有数据库连接。
  4. 添加代码生成项EF 5。x DbContext发生器,取代了。tt文件。
  5. 编写一些代码,从数据库中检索记录。

运行应用程序时,我得到了这个异常:

ConfigurationErrorsException:没有找到或加载注册。净框架数据提供商。

然后我添加引用MySql.DataMySql.Data.Entity6.7.4.0我库版本。NET 4.5项目。现在,当运行应用程序时,我得到一个不同的异常:

FileLoadException:无法加载文件或组装的MySql。数据、Version = 6.6.5.0 c5687fc88969c44d文化=中立,不能删除!请教如何解决这个问题”或它的一个依赖项。位于议会的清单定义不匹配装配参考。(从HRESULT例外:0 x80131040)

注意版本号,这不是MySQL连接器,我已经安装的版本。

我如何得到它正常工作?

诀窍解决这是:

  1. 添加引用MySql.DataMySql.Data.Entity库(6.7.4.0正确的版本。NET 4.5,在我的例子中)这一项目。
  2. 编辑machine.config与你的编辑器以管理员身份运行,和替换出现的所有MySQL版本6.6.5.0通过6.7.4.0 .

第二步,注意,有多个machine.config文件,一个用于每个框架版本(3.0,3.5,4.0)和结构(32位,64位)。还要注意的是machine.config文件。NET 4.5的。NET 4.0文件夹。你可以找到的machine.config文件:

C:Windows Microsoft.NET Framework 配置

和:

C:Windows Microsoft.NET Framework64 配置

如果没有对MySQL的引用machine.config文件,您可能没有安装MySQL为Visual Studio。这样做,或添加以下的app.config您的项目的文件:

<system.data>
    <DbProviderFactories>
        <add name="MySQL Data Provider"
            invariant="MySql.Data.MySqlClient"
            description=".Net Framework Data Provider for MySQL"
            type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
</system.data>
原文地址:https://www.cnblogs.com/wych/p/4087847.html