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

前端 未结 3 1937
一向
一向 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: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);
        }
    }
    

提交回复
热议问题