简体   繁体   中英

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

I have written an assembly in C# to perform all data access for a MySQL database. I have successfully used the assembly (a compiled dll) in my C# winform desktop application. But it only works on PCs that have had the "MySQL Connector Net 6.4.4" installed.

I tried to use the same assembly with my asp.net Website project. Firstly I got an error about a missing connection string. This was easily solved by adding the MySQL connection string to the web.config file. I now get this error (stack trace listed below), I have tried adding the following dlls to my bin folder to resolve it but it didn't work.

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 

But it only works on PCs that have had the "MySQL Connector Net 6.4.4" installed.

Does it mean that you are trying to run your code on machine where the provider is not installed? In such case you must also register the provider in your configuration file because installation adds it to machine.config and if you didn't install it the provider is currently not registered.

Try to add this to your web.config file:

<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>

I found I had this issue too when using the standalone .NET connector 6.6.5 installer.

To resolve, simply uninstall the standalone .NET connector installer, and install the mysql-community-installer, this installer lets you add/remove features to MySQL, and in it one of the features is the .NET connector that has Entity Framework support.

Once you use this connector all your MySQL EF issues go away.

Add this in web 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" />
    </DbProviderFactories>
  </system.data>

For people that reach this old question via Google like I did:

You will also get this error if you upgrade to MySQL for Visual Studio 1.1.3, which is the first compatible version with Visual Studio 2013, but still use MySQL Connector 6.6.6, which as far as I know is the last version that was compatible with Entity Framework 4.3.1.

We knew we had to update to EF5 (or 6) ASAP, but now this is forcing the change upon us at a very inconvenient time...

I had this error (I was using .net connector 6.4.3) after uninstalling all .net frameworks and reinstalling them. The fix was to uninstall 6.4.3 and install 6.6.5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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