MySql.Data.MySqlClient.Replication.ReplicationManager throws an System.TypeInitializationException

前端 未结 3 1914
一向
一向 2021-01-16 10:51

I\'m having trouble with my code to access a MySQL Database. Everytime I try to open my connection, a System.TypeInitializationException is thrown by MySq

相关标签:
3条回答
  • 2021-01-16 11:25

    I had the same problem but when i installed the MySql.Data.dll using Nuget then the problem is solved Install MySql.Dll file from Nuget,

    not from MySQL Website.

    0 讨论(0)
  • 2021-01-16 11:26

    In my case, it raised error only in production. It was due to a wrong assumption in the MySql.Data package. It for some reason seems to demand to be in the same folder as the orchestrating dll (it was referencing another dll which was referencing MySql). I resolved my issue by removing MySql.Data and instead installing MySqlConnector package as suggested in here.

    0 讨论(0)
  • 2021-01-16 11:40

    Your connection string format is wrong. Try this :

    static string cs = @"server=localhost;user id=bar;password=foobar;database=foo;";
    DataTable results = new DataTable("Results");
    using (MySqlConnection connection = new MySqlConnection(cs))
    {
        using (MySqlCommand command = new MySqlCommand(queryString, connection))
        {
            command.Connection.Open(); //throws System.TypeInitializationException
            command.ExecuteNonQuery();
    
            using (MySqlDataReader reader = command.ExecuteReader())
            results.Load(reader);
        }
    }
    
    0 讨论(0)
提交回复
热议问题