Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Connector with EF6 in Visual Studio 2013

Tags:

I am attempting to connect to MySQL through a C# .NET web MVC application.

My issue is that, when I attempt to add an ADO.NET Entity Data Model, generated from Database, based on my MySQL connection, I get the following error message:

Your project references the latest version of Entity Framework; however, an Entity Framework database provider compatible with this version could not be found for you data connection. Exit this wizard, install a compatible provider, and rebuild your project before performing this action

I'm running the following software, upgrades & add-ons:

  • Visual Studio 2013
  • MySQL Server v5.6.21
  • MySQL For Visual Studio v1.2.3
  • Connector/NET v6.9.4

NuGet packages:

  • EntityFramework v6.1.1
  • MySQL.Data v6.9.3
  • MySQL.Data.Entities v6.8.3.0
  • SQL.Web v6.9.3

My web.config, entityFramework block:

    .. </system.webServer> <entityFramework>   <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />   <providers>     <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />   </providers> </entityFramework> <runtime>     .. 

I have looked at all other solutions I could find here on SO and generally through google, tried all of them and none of the solutions seems to have worked or have been for very different versions of Connector/NET or other of the programs needed.

Can anyone spot what I am doing wrong?

like image 920
Olive Avatar asked Oct 09 '14 13:10

Olive


People also ask

Can I use Entity Framework core with MySQL?

To use Entity Framework Core with a MySQL database, do the following: Install the NuGet package. When you install either the MySql. EntityFrameworkCore or MySql.

Can I connect MySQL with C#?

Connect C# to MySQLAll the communication between a C# application and the MySQL server is routed through a MySqlConnection Object. So, before your application can communicate with the server, it must instantiate, configure, and open a MySqlConnection object.


2 Answers

I had the same issue. After installing:

  • Visual Studio 2013 Community Edition
  • MySQL for Visual Studio 1.2.3
  • MySQL Connector .NET 6.9.5

I didn't want to reinstall Visual Studio, so after some tests, I found that the folder "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies" contained old versions of the following files:

  • MySql.Data.dll
  • MySql.Data.Entity.EF6.dll
  • MySql.Web.dll

After closing Visual Studio, I replaced these files with those in "C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.5\Assemblies\v4.5", and now it works!

Note: replace 6.9.5 in the subfolder name above, with the actual version installed in your system.

like image 80
Alix Avatar answered Sep 19 '22 15:09

Alix


This worked for me WITHOUT reinstalling the Visual Studio or anything what so ever.

  • installed latest MySQL visual studio plugin and MySQL connector net
  • removed the entityFramework Tag in App.config or Web.config and all its child tags.
  • replaced it with the following code:
<entityFramework>   <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />   <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> 
  • added MySql.Data.dll, MySql.Data.Entity.EF6.dll, and MySql.Web.dll(if not WPF app) references to the project.
  • rebuilt the project and then added the ado.net model.

NOTE: Make sure you remove only the entityFramework tag and its children, and replace it with the snipped above. If you delete any "extra" tags you might have even bigger problems with your project, like I did. X)

like image 26
Stefan Vasiljevic Avatar answered Sep 20 '22 15:09

Stefan Vasiljevic