usr-local-ΕΨΗΕΛΩΝ
usr-local-ΕΨΗΕΛΩΝ

Reputation: 26894

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

Data Model wizard

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

Upvotes: 23

Views: 13028

Answers (12)

BrownPony
BrownPony

Reputation: 633

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

Upvotes: 0

rkawano
rkawano

Reputation: 2503

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:

  1. Close VisualStudio

  2. Uninstall (from Windows Control Panel):

    • MySQL for VisualStudio
    • MySQL Connector Net
    • MySQL Server
  3. Check PrivateAssemblies folder and delete any MySQL.* assemblies:

    • C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\PrivateAssemblies
  4. If needed, install MySQL Server version 5.7.33.

    • Workbench can be any version.
    • Setup your server.
  5. 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
  6. Install MySQL for VisualStudio 1.2.8

At this point, you can open VS and test generation of EntityFramework model

To build and run:

  1. Reference needed assemblies from the folder:

    • C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.8\Assemblies\v4.5
  2. Make sure your project target framework version is compatible with MySQL assemblies (v4.5)

  3. Look for MySQL references on your config files to point version 6.8.8

References:

Upvotes: 2

DavidRomo
DavidRomo

Reputation: 171

The problem is the compatibility of MySQL, Visual Studio, connector and MySQL for Visual Studio.


  1. Close Visual Studio.
  2. You need to uninstall MySQL Connector and MySQL for Visual Studio. (Restart your computer)
  3. If you have two versions of the visual studio it will work only in one of them. So choose which you want.
  4. 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
  5. Open VS and build your project then try to update your entities

enter image description here 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)

Upvotes: 2

Keep Thinking
Keep Thinking

Reputation: 141

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.

Upvotes: 3

MarkShep
MarkShep

Reputation: 171

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.

Upvotes: 2

BrownPony
BrownPony

Reputation: 633

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.

Upvotes: 1

DadyFuji
DadyFuji

Reputation: 253

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.

Upvotes: 0

Hsin-Yu Chen
Hsin-Yu Chen

Reputation: 59

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

Upvotes: -1

Nassif Bousaba
Nassif Bousaba

Reputation: 396

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

Upvotes: 2

BrownPony
BrownPony

Reputation: 633

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.

  1. Using nuget install MySql.Data 6.9.9 and MySql.Data.Entity 6.9.9. Nothing else.
  2. 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.

Upvotes: 2

James Wilkins
James Wilkins

Reputation: 7367

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

Upvotes: 0

Ian Newland
Ian Newland

Reputation: 1744

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

Upvotes: 3

Related Questions