繁体   English   中英

MySQL实体框架错误 - 在配置中找不到指定的商店提供程序,或者无效

[英]MySQL Entity Framework Error - The specified store provider cannot be found in the configuration, or is not valid

我在C#中编写了一个程序集来执行MySQL数据库的所有数据访问。 我在C#winform桌面应用程序中成功使用了程序集(已编译的dll)。 但它仅适用于安装了“MySQL Connector Net 6.4.4”的PC。

我试图在我的asp.net网站项目中使用相同的程序集。 首先我得到一个关于缺少连接字符串的错误。 通过将MySQL连接字符串添加到web.config文件可以轻松解决这个问题。 我现在得到这个错误(下面列出的堆栈跟踪),我已经尝试将以下dll添加到我的bin文件夹来解决它,但它不起作用。

MySql.Data.dll
MySql.Data.Entity.dll
MySql.Web.dll

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. 
---> System.ArgumentException: The specified store provider cannot be found in the configuration, or is not valid. 
---> System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed. at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) at System.Data.EntityClient.EntityConnection.GetFactory(String providerString) 
--- End of inner exception stack trace 

但它仅适用于安装了“MySQL Connector Net 6.4.4”的PC。

这是否意味着您尝试在未安装提供程序的计算机上运行代码? 在这种情况下,您还必须在配置文件中注册提供程序,因为安装会将其添加到machine.config,如果您没有安装它,则提供程序当前未注册。

尝试将此添加到您的web.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.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  </DbProviderFactories>
</system.data>

我发现在使用独立的.NET连接器6.6.5安装程序时也遇到了这个问题。

要解决此问题,只需卸载独立的.NET连接器安装程序,然后安装mysql-community-installer,此安装程序允许您向MySQL添加/删除功能,其中一个功能是具有Entity Framework支持的.NET连接器。

一旦使用此连接器,所有MySQL EF问题都将消失。

在web配置中添加此项

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

对于像我这样通过Google解决这个老问题的人:

如果为Visual Studio 1.1.3升级到MySQL,也会出现此错误,这是Visual Studio 2013的第一个兼容版本,但仍然使用MySQL Connector 6.6.6,据我所知,它是最后一个版本与Entity Framework 4.3.1兼容。

我们知道我们必须尽快更新到EF5(或6),但现在这迫使我们在非常不方便的时候改变...

在卸载所有.net框架并重新安装它们之后,我遇到了这个错误(我正在使用.net连接器6.4.3)。 解决方法是卸载6.4.3并安装6.6.5

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM