MySql.Data.MySqlClient.Replication.ReplicationManager引发System.TypeInitializationException [英] MySql.Data.MySqlClient.Replication.ReplicationManager throws an 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屋!