0

I have a C# windows form program, which I use EF in it that connects to MYSQL.

When I try to run the program, it gives me this error:

System.Data.Entity.Core.ProviderIncompatibleException: 'An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file.

This is my DBContext class:

using System.Data.Entity;

namespace ADMMassUploader
{
    public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext() : base("MySqlConnection")
        {
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
        public DbSet<adm_main> AdmMain { get; set; }
    }
}

This is my App.Config entries:

<?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.6.1" />
  </startup>
  <appSettings>
    <add key="connectionstring" value="Server=localhost;Port=3306;Database=mysql;Uid=root;Pwd=xxxxx;default command timeout=0;SslMode=none" />
    <add key="tempFolder" value="C:\\MySqlBackup" />
    <add key="s3Folder" value="C:\\S3" />
    <add key="excludeSchema" value="'information_schema','mysql','sys','.serversidedebugger','sakila','world','performance_schema'" />
    <add key="excludeTablePrefix" value="and table_name not like 'temp%' and table_name not like 'sample%'" />
    <add key="fromEmail" value="colinc@rassure.net" />
    <add key="fromDisplayName" value="Rassure Admin" />
    <add key="recipients" value="colinc@rassure.net,Colin Chin" />
    <add key="testbackup" value="Y" />
    <add key="testsql" value="select distinct table_schema from information_schema.tables where table_schema in ('cx_acdm')" />
  </appSettings>
  <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>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.11.0" newVersion="8.0.11.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <connectionStrings>
    <add name="MySqlConnection" connectionString="Server=localhost;Database=dev_test;Uid=root;Pwd=ibm2007;" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>  
</configuration>

This is my Button click function:

private void button1_Click(object sender, EventArgs e)
{
    using (var db = new ApplicationDbContext())
    {
        var query = db.AdmMain.Count();
        MessageBox.Show("Value=" + query);
    }
}

Anything that I am not doing right here? Help needed. Thanks.

1 Answer 1

0

Managed to find something from the MYSQL BUGS Forum at this link

In order to work around it, I had to downgrade to:

MySql.Data - 6.9.12 (6.10.7 and 8.0.11 exhibited the problem)

MySQL.Data.Entity - 6.8.8 (6.9.12 and 6.10.7 exhibited the problem)

MYSQL BUGS

Also, I need to add "[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]" to DBContext Class:

using System.Data.Entity;

namespace ADMMassUploader
{
    [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
    public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext() : base("MySqlConnection")
        {
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
        public DbSet<adm_main> AdmMain { get; set; }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.