Cannot connect to mysql from visual studio 2015

前端 未结 5 1011
忘掉有多难
忘掉有多难 2020-12-30 11:13

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 S

5条回答
  •  粉色の甜心
    2020-12-30 12:06

    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.)

    
    
    
    
    
    
    

    15) Make sure your DbProviderFactories section matches

    
      
      
    
    

    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.

提交回复
热议问题