The ADO.NET Provider with invariant name 'Mysql.Data.Mysqlclient' is either not Registered in the machine or application config file

Asked

Viewed 4,100 times

3

I have an MVC project, and I wanted to connect to the Mysql database. I put this connectionStrings.

<add name="Contexto" connectionString="server=127.0.0.1;User Id=xxxxxx;password=xxxxx;database=iesb_site" providerName="MySql.Data.MySqlClient" />

but every time I’ll do the Update-Migrations appears the following error:

The ADO.NET Provider with invariant name 'Mysql.Data.Mysqlclient' is either not Registered in the machine or application config file, or could not be Loaded. See the Inner Exception for Details.

  • Did you manage to solve the problem? You need something improved in the answer?

1 answer

9

To make the Entity Framework work with Mysql is not as simple as with SQL Server.

Before it is necessary to make some settings.

  1. Install the package Mysql.Data.Entity.EF6

    Install-Package Mysql.Data.Entity.EF6

  2. Edit the section <entityFramework> in the archive web config. (or app config.) and add the previous MySql.Data (example row 4 - replace the whole section by this one below should also work)

    <entityFramework>
      <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
      <providers>
        <provider invariantName="MySql.Data.MySqlClient" 
                  type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>
        <provider invariantName="System.Data.SqlClient" 
                  type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
      </providers>
    </entityFramework>
    
  3. Set a new class DbConfiguration for Mysql. This can be done in three ways:

    3.1. Adding the attribute DbConfigurationType in the current context class

    [DbConfigurationType(typeof(MySqlEFConfiguration))]
    public class MeuContexto: DbContext { }
    

    3.2. Calling DbConfiguration.SetConfiguration(new MySqlEFConfiguration()) whenever application is initialized. For example, in an ASP.NET MVC application, this code can be placed in the method Application_Start of the Global.asax archive.

    3.3. Reference to class MySqlEFConfiguration in the archive web config.

    <entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
    
  • Very good, it worked for me perfectly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.