No Entity Framework provider found for 'MySql.Data.MySqlClient' ADO.NET provider

entity-framework mysql

Question

I'm trying to use Entity Framework with MySQL and I get the above error. I have the latest MySQL connector installed.

The full error reads:

No Entity Framework provider found for 'MySql.Data.MySqlClient' ADO.NET provider. Make sure the provider is registered in the 'entityFramework' section of the application config file.

However, I can't find anything that suggests just how you register it in the 'entityFramework' section.

Some other posts (example) suggest adding the provider to the system.Data DbProviderFactories section like this:

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

But that doesn't work because it claims that the invariant name is duplicated. And, if I actually iterate through the System.Data.Common.DbProviderFactories I can see the last one is the MySQL provider:

MySQL Data Provider
.Net Framework Data Provider for MySQL
MySql.Data.MySqlClient
MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d

So the provider is there, but EF refuses to use it. Any ideas?

My full config looks like this:

<configuration>
    <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </configSections>

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

<connectionStrings>
    <add name="myContext" connectionString="server=****;User Id=****;password=****;Persist Security Info=True;database=myDb"
  providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>

</entityFramework>

</configuration>
1
32
5/23/2017 12:34:29 PM

Accepted Answer

Nevermind. I noticed that I had EF 6 installed. I removed it and tried EF 5 instead (which NuGet says is the latest stable version) and it started working.

Still, a more useful error message would have been nice!

0
2/28/2013 8:13:03 PM

Popular Answer

in EF5 or less, all ok. in EF6, you need to use mysql connector 6.8.x, and add DbConfigurationTypeAttribute to you DbContext:

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class DemoContext : DbContext{}

which MySqlEFConfiguration is in MySql.Data.Entity.EF6.dll in 6.8.x. Have a try!



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow