首页 > 解决方案 > 如何解决实体框架中的 system.data 配置问题

问题描述

如果将我的项目更新为 mysql.data 8.0.13 和 MySql.Data.EntityFramework。目标框架是 .net 4.5.2 EF 在 6.2 我现在有一个奇怪的行为,我必须将 system.data 部分添加到我的配置中

  <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" />
    </DbProviderFactories>
  </system.data>

然后它在一些机器上运行。但在其他人身上,你会得到以下错误。(翻译成英语,因为系统是德语)

System.Configuration.ConfigurationErrorsException: An error occurred when creating the configuration section handler for system.data: The column 'InvariantName' has the restriction that it must be unique. The value 'MySql.Data.MySqlClient' already exists. 

所以如果我删掉这部分配置,它就可以工作。但在另一台机器上它说。

System.ArgumentException: The ADO.NET provider with the invariant name 'MySql.Data.MySqlClient' was either not registered on the computer or in the application configuration file, or could not be loaded.  

有没有可能的解决方案或检查?因为我对同一台电脑上的不同用户也有奇怪的行为(通过 clickonce 推出)

EF的配置部分

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework"></provider>
    </providers>
  </entityFramework> 

这应该适用于任何电脑。我也不知道如何添加更多信息,因为我真的不知道问题出在哪里。整个周末都试图解决这个问题。

标签: c#mysql.netentity-framework

解决方案


我不太确定,但你可以试试这个:

从 System.data 元素:

添加这个:

<remove invariant="MySql.Data.MySqlClient" />

好像:

<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=6.8.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>

您可以包含该版本或删除您的版本。

但是,如果您包含该版本,请确保它是您正在使用的 MYSQL 版本。


推荐阅读