Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework using the wrong connection provider

I am trying to use Entity Framework 5 (code-first) for an ASP.NET Web Forms application, I have previously had a basic implementation running using the MySQL connection and I have also had success working with a desktop application using SQL Server Compact 4.

The problem I am having is that with EF5 I am getting the error

The specified store provider cannot be found in the configuration, or is not valid.

which is very little help.

Upgrading to EF6-rc1 gives me the more useful error of

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.

At least I now know what the "problem" is.

The issue I have is that I have removed all trace of MySQL from the project, there is no reason why the project should be trying to load the MySQL provider.

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="System.Data.SqlServerCe.4.0" />
  </parameters>
</defaultConnectionFactory>
<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>

<connectionStrings>
<add name="im_customerdb" connectionString="Data Source=|DataDirectory|\CustomerData.sdf" providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>

These are excerpts from my web.config file, please let me know if there are any other relevant sections that might point at the solution.

I have done a text search through every file in the solution for the word MySQL and there are no references to MySQL. I have checked a clean version of the project out of source control to be sure that I haven't missed a file when purging the project build files.

Can anyone provide any clues as to where I should look to determine why EF is insisting on loading a MySQL provider?

Regards, Anthony

*Edit: * Just to add that the exception is thrown the first time the database context is accessed, from the stack trace the exception is being thrown when the database is being initialised. I've also noticed something very peculiar; the database file is being created correctly, it just seems that EF then refuses to use it and tries to use MySQL.

like image 514
Anthony Avatar asked Oct 01 '13 07:10

Anthony


1 Answers

Questions is old, but may be this will be helpful for somebody.

I've got the same issue with transition from Oracle to MS SQL Server. Eventually, it appeared that code migrations were the root cause of the issue. You cannot just leave them as is after switching to another database provider. So, you must REGENERATE migrations for your new database provider.

like image 165
Oleksandr Kobylianskyi Avatar answered Sep 21 '22 14:09

Oleksandr Kobylianskyi