0

My goal here is to generate a model (the .edmx file) from EF 6 using MySQL in a Console Application. Every time after I click the Finish button in the Entity Data Model Wizard to generate the model, I get an EntityCommandExecutionException. I have been everywhere on Stack Overflow and google trying to find a solution to this but I could not find any.

In my 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 -->
    <!-- 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.7.2" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="MySql.Data.EntityFramework.MySqlConnectionFactory, MySql.Data.EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.21, 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=8.0.21, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="worlddb" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;user id=root;database=world" />
  </connectionStrings>
</configuration>

Entity Data Model Wizard

Entity Data Model Wizard

Entity Data Model Wizard Throwing Exception

In the output console it logged: Unable to generate the model because of the following exception: 'System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: Fatal error encountered during command execution. ---> MySql.Data.MySqlClient.MySqlException: Fatal error encountered attempting to read the resultset. ---> MySql.Data.MySqlClient.MySqlException: Reading from the stream has failed. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

Edit: The Console Application does not have any other code except the Program.cs (an empty Main method inside Program.cs) and the App.Config. All of the required packages (MySql.Data and MySql.Data.EntityFramework with the same version) are added.

B.Anderson
  • 21
  • 6
  • 1
    Instead of localhost in connection string use the IP address of machine or computer name. Localhost may not be configured correctly. – jdweng Sep 08 '20 at 17:59
  • 1
    Are remote connections enabled? – devlin carnate Sep 08 '20 at 18:13
  • @jdweng I have tried it but it did still gave me the same result. – B.Anderson Sep 08 '20 at 18:23
  • 1
    Does this answer your question? [Unable to read data from the transport connection : An existing connection was forcibly closed by the remote host](https://stackoverflow.com/questions/5420656/unable-to-read-data-from-the-transport-connection-an-existing-connection-was-f) – devlin carnate Sep 08 '20 at 18:24
  • @devlincarnate I have looked into the firewall and there were none of the Remote features enabled – B.Anderson Sep 08 '20 at 18:39
  • 1
    That thread isn't just suggestion firewall...and in addition to that thread, have you verified that your mysql instance has been configured for remote connections? That's not enabled by default... – devlin carnate Sep 08 '20 at 19:32
  • @devlincarnate ok I have been on a bunch of articles including Stackoverflow on how to allow remote connections to MySQL Server and still none of those worked. I don't know what am I missing. – B.Anderson Sep 09 '20 at 08:55

0 Answers0