我使用nuget安装了mysql.data 8.0.28
使用最简单的连接语句
static public bool TestConnect()
{
using (MySqlConnection conn = new MySqlConnection("Database =a;Data Source=10.14.12.131;Port=3306;User Id=root;Password=root;SslMode = none;allowPublicKeyRetrieval=true;CharSet=gbk"))
{
try
{
conn.Open();
conn.Close();
Console.WriteLine("ok");
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
}
return false;
}
直接运用不会有任何问题,正常打印出ok
但是一旦发布时选择生成单个文件,立即触发以下异常
The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.
at MySql.Data.MySqlClient.Replication.ReplicationManager.IsReplicationGroup(String groupName)
at MySql.Data.MySqlClient.MySqlConnection.Open()
at onefiletestmysql.Program.TestConnect()