MySql.Data.MySqlClient.Replication.ReplicationManager 抛出 System.TypeInitializationException [英] MySql.Data.MySqlClient.Replication.ReplicationManager throws an System.TypeInitializationException

查看:44
本文介绍了MySql.Data.MySqlClient.Replication.ReplicationManager 抛出 System.TypeInitializationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码无法访问 MySQL 数据库.每次我尝试打开我的连接时,MySql.Data.MySqlClient.Replication.ReplicationManager 都会抛出一个 System.TypeInitializationException.这是我的代码:

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 MySql.Data.MySqlClient.Replication.ReplicationManager. Here is my code:

DataTable results = new DataTable("Results");
using (MySqlConnection connection = new MySqlConnection("SERVER=127.0.0.1;DATABASE=foo;UID=bar;PASSWORD=foobar;"))
{
    using (MySqlCommand command = new MySqlCommand(queryString, connection))
    {
        command.Connection.Open(); //throws System.TypeInitializationException
        command.ExecuteNonQuery();

        using (MySqlDataReader reader = command.ExecuteReader())
        results.Load(reader);
    }
}

我猜 MySQL 驱动程序已损坏.从 Windows 7 升级到 Windows 10 后一切正常.

I guess MySQL Driver was corrupt. After an upgrade from Windows 7 to Windows 10 everything worked fine.

推荐答案

我遇到了同样的问题,但是当我使用 Nuget 安装 MySql.Data.dll 时,问题就解决了从 Nuget 安装 MySql.Dll 文件,

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,

不是来自 MySQL 网站.

not from MySQL Website.

这篇关于MySql.Data.MySqlClient.Replication.ReplicationManager 抛出 System.TypeInitializationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆