MySql Connector with EF 6 - mysql

I am having a weird issue with MySql Connector(6.8.3) and EF6. I was working on a WebApi project where I use MySql and EF6 with Database first approach. Everything worked fine[even deployed on one of the test servers] until I changed the database from 'Test' database to 'Production' database [just the database name] in the connection string and updated the model[just to see nothing is broken!]. After that, it failed to connect to database. So, I changed the connection string back and rebuilt the solution, then I got bunch of 'Mapping' warnings. I deleted the model and tried to create the model again from the database. Now, I am getting the following 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
Here is the config file
<!-- 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>
<clear/>
<remove invariant="MySql.Data.MySqlClient"/>
<add name="MySql.Data.MySqlClient" description="ADO.Net driver for MySQL" invariant="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,Version=6.8.3.0, Culture=neutral,PublicKeyToken=c5687fc88969c44d"/>
</DbProviderFactories>
</system.data>
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
<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>
I tried reinstalling the connector and EF from Nuget, but nothing changed. Can someone please let me know whats going on?
Thanks

I had a similar issue, I had the MySql connector referenced to my project with Nuget. But the server had another version of MySql connector installed in the machine itself. So the application gave priority to the MySql connector installed in GAC of server.
All you have to do is either
Uninstall the MySql connector in Server
or
Install suitable MySql connector (in your case v6.8.3) in server and uninstall the rest
or
change your provider type version to one that is installed in the server.

Bloody hell, had the same issue.
I'm pretty new to the .NET environment so, I don't know how the packages manager and all work but it seems that when I import the assemblies for the MySQL connector, it updates the "web.conf" file with the wrong parameters for the provider.
In my case, using EF6 and MySQL Connector for EF v6.8.3.0, the following worked for me :
<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>
</providers>
</entityFramework>
Hope it helps someone

i know what the problem is, you have to do the next steps :
1. Right click on the project
2. Manage NuGet Packages
3.remove the MySql.Data
4.now you can do what you wanted to do
5.after you finish, go back to Manage NuGet Packages and add MySql.Data.Entity
:)
good luck
nofar eliasi

Related

Visual Studio 2015 Only Shows SQL Server Connections When Trying to Create an ADO.NET Entity Model Class

I have previously created an instance of a MySQL database as described in this question on Code Review. I have completed the database, and I’m ready to create the application using C# in Visual Studio 2015.
The only question I’ve found here on stackvoverflow.com that seems relevant is this one.
I have been using MySQL Documentation from these pages:
Connector Instalation using Nuget
Connector / NET Entity Framework 6.0
Environment is Windows 10, The regedit image shows the .net framework version. I upgraded MySQL to version 8.0.11 earlier this week.
Package Manager Console:
PM> get-package
Id Versions ProjectName
-- -------- -----------
EntityFramework {6.2.0} bkInventory2App
Google.Protobuf {3.5.1} bkInventory2App
MySql.Data {8.0.11} bkInventory2App
MySql.Data.EntityFramework {8.0.11} bkInventory2App
App.config
<?xml version="1.0" encoding="utf-8"?>
<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>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<connectionStrings>
<add name="MySQLBKLibInventory" providerName="MySql.Data.MySqlClient" connectionString="SERVER=localhost;DATABASE=pacswlibinvtool;UID=root;PASSWORD=******;" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, 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>
</configuration>
Dot Net Version
Add ADO.NET Class
Choose Model Contents
Choose Data Connection
Choose Data Source
ODBC Data Administrator
Installed MySQL Applications
Database in MySQL WorkBench
Please note in the second to last image, the one showing the installed MySQL Applications, that MySQL for Visual Studio is not installed. Installing MySQL Visual Studio corrected this particular configuration problem.

Cannot connect to mysql from visual studio 2015

So I have already spent about 2 days trying fix this. I have succeeded in fixing this on my workplace pc and can't get it to work on my home pc. I have read about a dozen SO articles and oracle forums articles and whatnot but still it does not work.
I have 1.2.4 msql for visual studio which is supposed to be a release which works on vs2015. I have installed mysql connector 6.8.6 and have first tried to add mysql to my project via nuget but after not being able to find a 6.8.6 version (there are 6.8.3 and 6.9.7 for one package and then again something else for the other...) I have referenced to my C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.6\Assemblies\v4.5 and have taken the 4 files there and have copied them ove the whole fkin computer. I have pasted it like everywhere. The vs2013 private assembly, my packages folder which I do not even reference to anyway and I think some vs2015 folder. I have ran a search for Mysql.Data and have pasted these files in every folder that came up as a result. I have rebuilt the solution for about 100-200 times and have cried for at least 20 minutes.
What do I have to do to get my new ADO.Net Entity Data Model generated?
I keep getting this stupid
image and I have really absolutely no idea what to do next. I just want to code but every time I start doing something I keep wasting days on tools not working. Do I really have to code in notepad so that I am sure it's my fault that something isn't working?
This is my app.Config file. I do not have anything else in my project.
<?xml version="1.0" encoding="utf-8"?>
<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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v12.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<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, Version=6.8.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.8.6.0" newVersion="6.8.6.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<connectionStrings>
<add name="KPlusConnectionString" connectionString="server=dito.ninja;user id=xxx;password=xxx;database=xxx" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
</configuration>
In order for VS 2015 to connect to MySql you need to be using a later version of the MySql libraries. While that seems like a pretty simple answer, in all honesty I have run into several problems along the way. With that in mind I am going to write out the 1 process that has consistently worked for me as far as getting EF working with MySql and VS2015. So, without further ado, here are the steps I have been taking in order to get this to work.
1) Make sure the MySql connector installation is updated
2) Create your web project
3) Open Nuget
4) Install Entity Framework
5) Search for MySql
6) Install MySql.Data
7) Install MySql.Data.Entity
8) Install MySql.Data.Entities
9) Install MySql.Web
10) Go to the references for the project and delete MySql.Data.Entity.EF6
11) Check the versions of the MySql.Data and MySql.Web libraries. If they are under 6.9.6 delete them as well
12) Add a new reference by browsing to the install location for the mysql connector for your version of the .NET framework (mine is C:\Program Files (x86)\MySQL\Connector.NET 6.9\Assemblies\v4.5) and grabbing the MySql.Data.Entity.EF6.dll (my version is 6.9.6, keep that in mind when we change the web.config later)
13) If the other libraries were also older versions, add references to them by browsing to the packages folder in your solution and grabbing the files from their respective folders. I do not normally have to do this.
14) Now the Web.config will need to be edited. The first step is to replace the entity framework section with this code (change the version number to your current version. Please note that I found this snippet on the web a couple weeks ago and do not have the original link. I apologize to the original poster of this information.)
<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, Version=6.9.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</providers>
</entityFramework>
15) Make sure your DbProviderFactories section matches
<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, Version=6.9.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
16) Save and build
I am not sure how many of these steps are actually required but after finally getting it once I had to actually get some work done and didn’t have time to narrow things down further. Hopefully that gets you moving.
P.S. If after all of that you go through the wizard and it just disappears before it shows you the tables in the database to create entities from then it could be one of three problems I have run into along the way. The database server cannot be contacted. The user does not have the needed permissions on the database. The wrong version of MySql.Data.Entity.EF6 was added as a reference or the version number is wrong in the web.config. If I grab this file from the packages directory of my solution I often run into this aborted-wizard-with-no-error-message problem. Grabbing it from the MySql install directory has worked fine for me every time.
It works for me.
I have Visual Studio 2015, and just installed latest version of connector:
http://dev.mysql.com/downloads/windows/visualstudio/
Read this more carefully:
http://dev.mysql.com/doc/relnotes/mysql-for-visual-studio/en/visual-studio-news-1-2-4.html
They mention that version of "Microsoft ASP.NET MVC" could be a problem.
Wrong is that they say VS2015 ships with version 5, but I have version 4 installed with VS2015 Enterprise final.
Tried this and it didn't work for me. What eventually worked was making sure I had the right driver. I run a 64bit Windows 7 computer. I eventually had to install the 32bit version of the MySQL ODBC connector/driver and used the following connection string "Provider=MSDASQL; Driver={MySQL ODBC 5.3 ANSI Driver}; Server=localhost; Database=xxxx; User=xxxx; password=xxxx; Option=3;" and that solved it. tested it on a new project without making all the above changes, and it worked just fine. This post was super helpful in explaining this: https://support.microsoft.com/en-us/kb/942976. Hope this saves someone a lot of time
install the package from this site. http://dev.mysql.com/downloads/windows/visualstudio/ in the Development release tab.
I stopped Visual Studio.. I installed. WAITED.. Seams to take for ever. Visual studio will be running in the background.
Wait till completed.
reopen Visual Studio. boom back in play!
Good luck !
For VS2015 I removed all version installed and through the MySql Installer - Community. I selected Customize Installation and selected MySQL Connectors to install: 1. MySql for Visual Studio 2) MySQl ConnectorNet.
I added references: MySql.Data y MySql.Data.Entity.EF5 both in
C:\Program Files (x86)\MySQL\Connector.NET 6.9\Assemblies\v4.5\
Recompiled the project And When creating de ADO.Net Object the famous MySql data provider was shown!
A warning was displayed about Entity Frame Versions, I just clicked Next And worked![enter image description here][1]

Entity Framework wizard crashes on MySQL

My question is similar to this one but the crash happens later. I must interoperate an EF database-first model between SQL Server and MySQL. More specifically, my application had plain SQL queries fired to either SQL Server or MySQL according to connection string and configuration setting (DB_TYPE=MYSQL, etc.), having both databases with same structure and maintained together, so that each modification to one's schema was reapplied to the other.
Now I added EF support to the application using SQL Server database-first model. I must now let the application run on MySQL too. In order to verify that the old developer didn't leave something disaligned between the two DBMSes, I tried to Update model against database* and this time I selected the MySQL connection to my development database on localhost.
After I click Next on the screen below, it will simply crash and return to EDMX editor
I need to go ahead with the project, I'm stuck on this since a while.
Here is my Web.config fragment:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<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, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
How can I solve my problem? I reinstalled MySQL tools for Visual Studio but didn't help.
*I use a localized version of Visual Studio, so I don't know the original English for all commands
I have no idea why this works but I went in to my NuGet Package Manager and removed the MySql.Data.Entity (also checked dependencies which removed MySql.Data). I went into my .edmx and ran the 'Update model from database...' and everything worked.
(Note: This also removed my entity framework so I had to add that back in using the NuGet Manager)
W...T...F?
Maybe others can confirm this...
It has been answered in another thread, the typical crash reason is the mismatched versions of MySQL connector and MySQL.Data.Entity.
And most likely reason for you to get the wrong version is because of the package name changed from MySQL.Data.Entity to MySql.Data.EntityFramework.
I was spending a lot of time on trying the answers in the thread, so just FYI.
When you look around this seems to be a common problem. I know this way along the trail but late is better then never.
I eventually removed and reinstalled visual studio 2015 and mysql and then started from scratch. I then ensured that I walked through the process bringing in only what was needed.
Using nuget install MySql.Data 6.9.9 and MySql.Data.Entity 6.9.9. Nothing else.
Nuget does not change the web config correctly so you need to change it as below.
Before
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
After
<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, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>
</entityFramework>
This fixed it for me. I am not sure that you need do the reinstall, but for sure you need do step 2.
Good luck.
I fixed this problem by following the steps below (note that im using vs2015 and .net 4.5)
1) Uninstall all previous mysql connectors that you have
2) Remove all mySQL references through NuGet packages
3) Download mysql connector v6.8.8
4) Once this is downloaded, go to your project and add as reference the newly installed dll files (located in the installation path, typically C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.8\Assemblies\v4.5)
5) Go to your NuGet packages and add MySql.Data (Version 6.8) and MySql.Data.Entity (Version 6.8).
6) Build your solution and no more crash :)
Hope this helps you out
For anyone who's still encountering this issue here are the versions that I had to install to get it working:
MySQL for Visual Studio: 2.0.5 (note that at the time of posting the latest General Availability release is 1.2.9 - you'll need to go to the Development Releases tab to get version 2.0.5 - https://dev.mysql.com/downloads/windows/visualstudio/)
MySQL Connector/NET: 6.9.11 (https://downloads.mysql.com/archives/c-net/)
MySQL.Data NuGet package: 6.9.11 (Install-Package MySql.Data -Version 6.9.11)
MySQL.Data.Entity NuGet package: 6.9.11 (Install-Package MySql.Data.Entity -Version 6.9.11)
(Note that I didn't have to adjust the config file.)
Hope it helps.
The problem is the compatibility of MySQL, Visual Studio, connector and MySQL for Visual Studio.
Close Visual Studio.
You need to uninstall MySQL Connector and MySQL for Visual Studio. (Restart your computer)
If you have two versions of the visual studio it will work only in one of them. So choose which you want.
Install the correct versions. (Restart your computer).
Visual Studio 2019 (Community, Professional, and Enterprise)
- MySQL for Visual Studio 1.2.9 with Connector/NET 8.0.14
Visual Studio 2017 (Community, Professional, and Enterprise):
-MySQL for Visual Studio 1.2.7 with Connector/NET 6.9.9
Visual Studio 2015 (Community, Professional, and Enterprise):
-MySQL for Visual Studio 1.2.7 or 2.0.2 with Connector/NET 6.9.8
Open VS and build your project then try to update your entities
Actually I'm using VS professional 2017 with this nuggets MySql.Data 6.9.9 and MySql.Data.Entity 6.9.9(MySQL for Visual Studio 1.2.7 with Connector/NET 6.9.9)
In my case, the trouble was a specific version of MySQL Server. So I have uninstalled everything and made a clean install with these versions.
This is the setup that worked with VisualStudio 2019 Community:
Close VisualStudio
Uninstall (from Windows Control Panel):
MySQL for VisualStudio
MySQL Connector Net
MySQL Server
Check PrivateAssemblies folder and delete any MySQL.* assemblies:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\PrivateAssemblies
If needed, install MySQL Server version 5.7.33.
Workbench can be any version.
Setup your server.
Install MySQL Connector Net 6.8.8
This version is not available at MySQL archives. You can find mirrors looking for the name: mysql-connector-net-6.8.8.msi
Install MySQL for VisualStudio 1.2.8
At this point, you can open VS and test generation of EntityFramework model
To build and run:
Reference needed assemblies from the folder:
C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.8\Assemblies\v4.5
Make sure your project target framework version is compatible with MySQL assemblies (v4.5)
Look for MySQL references on your config files to point version 6.8.8
References:
Nassif Bousaba answer
https://bugs.mysql.com/bug.php?id=89338
Well I can tell you that connector 8.0.xxx and all of the 8.0.xxx dll's that MySQL has put out for MySql Server 8 are a complete bust.
There has been a major bug out https://bugs.mysql.com/bug.php?id=91030&thanks=3&notify=195 for over a year now.
If your trying to work with MySql 8.0 many of the connectors and libraries will give you an error....
"The provider did not return a ProviderManifestToken string."
It is a testament to the absolutely sub zero level of visual studio support, documentation, testing and basic development skill applied in the mysql dll's connector and documentation that I have spent the last 40 hrs of my waking life trying to put together a working model to get my application to connect with MySql 8.0.16 and to have a working entity framework wizard. At this point I am almost wishing I developed it using SQL Server.
I am using a variant of ASP.NET Identity 2.0 and this is what I would get back when trying to log in
"The provider did not return a ProviderManifestToken string."
Anyway here is what I got to work for me.
This is something I got to work with Server 8.0 on Windows 10 that does a connection and allows log in with ASP.NET Identity 2.0 and will at least run the Data Entity Wizard to completion.
Install Connector / Net 6.10.7
DLL's
c:..\EntityFramework.6.2.0\lib\net45\EntityFramework.dll
C:..\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll
C:..\MySql.Data.6.10.7\v4.5.2\MySql.Data.dll
C:..\MySql.Data.6.10.7\v4.5.2\MySql.Data.Entity.EF6.dll
Web.Config
<configSections>
<section name="entityFramework"type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral,publicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="server=localhost;user id=<yourid>;password=<yourpassword>;persistsecurityinfo=True;database=<yourdbname>" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.10.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient"></remove>
<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.10.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
I hope this helps some people out there but I have a funny feeling your mileage may vary.
I had a similar issue. After installing 'MySql.Data 6.9.9' and 'MySql.Data.Entity 6.9.9' Nuget packages, the wizard crashed after that screen. I attached a debugger to it and found it was caused by a null reference exception in MySql.Data.Entity.EF6.dll.
I figured it may not be the packages, since I already tried reinstalling them, so I figured it might be an issue with the MySQL install for Visual Studio conflicting with the MySQL EF6 dll. The solution for me was simply to reinstall the latest "MySQL for Visual Studio 1.2.6":
http://dev.mysql.com/downloads/windows/visualstudio/
Could be I had an older version (didn't think to check first, so I can't confirm).
In my case, the cause was that the version of the installed mysql connector was different from the version of referenced MySQL.Data.Entity
When I referenced the same version all became alright.
Not sure how the link will remain around but this works very well for .net core.
https://www.c-sharpcorner.com/article/tutorial-use-entity-framework-core-5-0-in-net-core-3-1-with-mysql-database-by2/
In summary the trick seems to be to use
Microsoft.EntityFrameworkCore (v5.0.0 – the latest stable version)
Microsoft.EntityFrameworkCore.Tools (v5.0.0 – the latest stable version)
Pomelo.EntityFrameworkCore.MySql (version 5.0.0-alpha.2)
in your in your package manager. Made it pretty smooth.
I have been seriously unimpressed by other releases that are not Pomelo.
Using MySQL Connector Net 6.10.7 and Server 8.0
I change config file from
<entityFramework>.....</entityFramework>
to
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">.....</entityFramework>
and everything works
reference:https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html

Using MySQL & MSSQL for two different databases with Entity Framework

I am trying to build a web api that serves data from either a MySQL database or a MSSQL database (completely different data and schema). It also provides some endpoints for moving data between the two. I have created two class libraries to hold the EF models for both databases and have been successful in connecting to both instances and running queries against both. Where it falls down is trying to access both of them. I have to tweak the web.config entityFramework section to get either to work, I can't get it so that both work at the same time effectively. I am using EF6 and the latest MySQL connector.
This is the working config for MSSQL entities:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<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>
This is the error it produces when I try to use the MySQL entity context
The default DbConfiguration instance was used by the Entity Framework before the 'MySqlEFConfiguration' type was discovered. An instance of 'MySqlEFConfiguration' must be set at application start before using any Entity Framework features or must be registered in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=260883 for more information.
This is the working config for MySQL entities:
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
<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" />
This then complains about the connection string as its trying to use the MySQL libraries. I can't find much online about this, this question here is similar but there was no answer to it: Is it possible to have a EF Context for MySql and SqlServer?
Has anyone done this or know of a way round the issue?
To resolve this error i put this on my App.config: "codeConfigurationType"
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
Why? Possible the Configurations is not fiding the location of MySqlEFConfiguration.
Im using here only Mysql, i dont know if this work on SQLServer and Mysql togueter.
For your problem this link can be useful: Link
And you can have 2 separeted configuration.cs Files. One for MySql and other for MSSQL
The issue appears to have been addressed in the beta MySQL connector at the time of writing this, version 6.9.1. I now have the two running side by side without any problems.
Update
For clarification the setup I have is EF5 (EF6 won't work) and the MySQL connector version 6.9.1 (beta). my web.config section looks like this:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
The model's are located in the same project, again I have had difficulty with class libraries.
I had the same issue. I'm using migrations in my code first project with two db contexts for mysql and mssql. The issue is because EF6 tries to find db configuration in config file or in the same assembly where db context is. For mysql migrations I use MySqlHistoryContext that inherits from DbContext. During db initialization stage EF6 creates instance of MySqlHistoryContext and find MySqlEFConfiguration type and tries to use it.
I found two ways to solve the issue. The first is disabling migrations checks by call Database.SetInitializer with null argument. The second is inherit from MySqlHistoryContext in my own assembly. The second seems to work for me.
I chased down all the solutions I could find on SO and elsewhere, and for me the issue turned out to be my MSSQL connection string.
before:
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Server=serverName/instance;Database=PublicWebsite;Integrated Security=True;" />
after:
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=serverName/instance;Initial Catalog=PublicWebsite;Integrated Security=True;" />
The "before" connection string worked fine for EF. The problem presented after we introduced MySQL for EF (in a different class library).
To be clear, in MSSQL the connection string we just changed "server" to "data source" and we changed "database" to "initial catalog".

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

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>
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!
You need to create this section in config (EF 5):
<entityFramework>
<!-- ... -->
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity" />
</providers>
</entityFramework>
Update: Use this definition for EF 6:
<entityFramework>
<!-- ... -->
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>
Thanks to elcool.
I just had the same situation when trying to configure Visual Studio Professional 2017 environment with MySQL, ADO.NET (Database First) and EF6.
After going through hell with every connector/NET available, I got it to work with Connector/NET v6.9.10 and following the steps below.
Uninstall/remove "Connector/NET" and "MySQL for Visual Studio" if installed.
Install "MySQL for Visual Studio" v2.0.5 CTP (MySQL for Visual Studio).
Note: Install MySQL for Visual Studio before Connector/NET.
Install "Connector/NET" v6.9.10 (Connector/Net).
https://i.stack.imgur.com/XOT1I.jpg Note: I tried using Connector/NET v6.8, v6.10 and v8 first, but none of them worked Here you can find all Connector Versions and Compatibilities with Visual Studio IDEs, but so far this list is inaccurate.
Download and Install "EntityFramework" v6.2.0 through NuGet.
Add references to C:\Program Files (x86)\MySQL\Connector.NET 6.9.10\Assemblies\v4.5\MySql.Data.dll
and
C:\Program Files (x86)\MySQL\Connector.NET 6.9.10\Assemblies\v4.5\MySql.Data.Entity.EF6.dll.
Add MySQL EF6 provider info inside App.config under entity framework providers as follow:
<entityFramework>
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>
Rebuild project.
And that was it. VS2017 was ready to go for me. Hope this works for everybody, as it did for me today.
References:
Can't Create Entity Data Model - using MySql and EF6
No Entity Framework provider found for 'MySql.Data.MySqlClient' ADO.NET provider
Just adding a summary of versions (since I saw you are trying 6.2 which is way too old)
For EF4, use Connector/NET 6.6.x (current GA is 6.6.6)
For EF5, use Connector/NET 6.7.x (current GA is 6.7.4) or Connector/NET 6.8.x (current GA is 6.8.3).
For EF6, use Connector/NET 6.8.x (current GA is 6.8.3).
I've updated from EntityFramework 5.0 to 6.1 and MySQL connector 6.8.3 and only had to add the attribute to get things going again. Before adding the attribute everything would compile fine but crash at runtime.
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class DemoContext : DbContext{}
I tried every different combination of config string and setup but I finally figured it out. My solution has the source code in one project and tests in another. I was using Entity Framework 6.1.1 and had installed MySql Connector 6.8.3 and MySql for Visual Studio 1.2.3.
The problem was that I had NuGet managing the packages, but only had them included in the main project. The solution was to
Right click on the Solution (top level in the solution explorer)
Manage Nuget packages for solution
Go to Installed tab
For all of the EntityFramework related packages (MySql.Data, MySql.Data.Entities, MySql.ConnectorNET.Entity and MySql.ConnectorNET.Data), select them then select the "Manage" button.
Enable each package for all projects.
For future reference, here's the official guide on using MySQL Connector/Net with EF 6 which includes all the necessary steps (assemblies, configs, ...etc.):
Chapter 10 EF 6 Support
Install latest version from nuget
https://www.nuget.org/packages/MySql.Data.Entity/
In my case, it was a missing reference. When you upgrade to EntityFramework 6, you need to add a reference to the assembly
System.Data.Entity
I think it's because MySql.Data.Entity.EF6 inherits from a bunch of stuff in this assembly, that it did not for previous version of EF.
When your app.config is good and all your references seem fine, it's a solution worth checking.
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!
May just MySql provider is installed in machine-config (e. g. by .net connector installer?
Also the default connection factory should be something like "MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" i guess...