Cannot connect to mysql from visual studio 2015 Cannot connect to mysql from visual studio 2015 mysql mysql

Cannot connect to mysql from visual studio 2015


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