SQL_ERROR: The type initializer for #39;MySql.Data.MySqlClient.MySqlConnectAttrs#39; threw an exception(SQL_ERROR:“MySql.Data.MySqlClient.MySqlConnectAttrs的类型初始化程序引发异常)
问题描述
我的 C# 代码和 MySQL 有错误.你能帮我解决吗?
I have an error with my C# code and MySQL. Can you help me solve it please ?
这是我的代码:
try
{
using (MySqlConnection dbcon = new MySqlConnection(SQLConnectionString))
{
dbcon.Open(); // ERROR HERE
string sql = "SELECT * FROM scp_patreons";
MySqlCommand command = new MySqlCommand();
command = dbcon.CreateCommand();
command.CommandText = sql;
using (MySqlDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
string fullname = (string)dr["fullname"];
plugin.Info("Name: " + fullname + "");
}
}
}
}
catch (Exception ex)
{
plugin.Info("SQL_ERROR: " + ex.Message + "
" + ex.StackTrace);
}
string SQLConnectionString = "Server=*; Database=*; User ID = *; Password=*; Pooling=false;SslMode=None;";
我得到了错误:
SQL_ERROR: The type initializer for 'MySql.Data.MySqlClient.MySqlConnectAttrs' threw an exception.
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)
at MySql.Data.MySqlClient.NativeDriver.SetConnectAttrs () [0x00018] in <699dc28794d34867bd2008187eb8039c>:0
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate (System.Boolean reset) [0x00080] in <699dc28794d34867bd2008187eb8039c>:0
at MySql.Data.MySqlClient.NativeDriver.Authenticate (System.String authMethod, System.Boolean reset) [0x0002a] in <699dc28794d34867bd2008187eb8039c>:0
at MySql.Data.MySqlClient.NativeDriver.Open () [0x0033f] in <699dc28794d34867bd2008187eb8039c>:0
at MySql.Data.MySqlClient.Driver.Open () [0x0000e] in <699dc28794d34867bd2008187eb8039c>:0
at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x0004e] in <699dc28794d34867bd2008187eb8039c>:0
at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0016d] in <699dc28794d34867bd2008187eb8039c>:0
at PlayerXP.PlayerXP.OnEnable () [0x00021] in <80e302c4eac64aeebd42276ff4a14839>:0
我正在运行 5.7.25 - MySQL 社区服务器 (GPL)
服务器:带有 UNIX 套接字的本地主机协议版本:10
用户:root@localhost
服务器字符:UTF-8 Unicode (utf8)
Mono JIT 编译器版本 5.18.0.268
连接器/NET 8.0.15
我使用 Debian 9.6.
I'm running 5.7.25 - MySQL Community Server (GPL)
Server : Localhost with UNIX socket
Protocol version : 10
User : root@localhost
Server char : UTF-8 Unicode (utf8)
Mono JIT compiler version 5.18.0.268
Connector/NET 8.0.15
I use Debian 9.6.
感谢您的帮助.
新的错误信息:
System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.MySqlConnectAttrs' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
at MySql.Data.MySqlClient.MySqlConnectAttrs..cctor () [0x0000f] in <699dc28794d34867bd2008187eb8039c>:0
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)
at MySql.Data.MySqlClient.NativeDriver.SetConnectAttrs () [0x00018] in <699dc28794d34867bd2008187eb8039c>:0
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate (System.Boolean reset) [0x00080] in <699dc28794d34867bd2008187eb8039c>:0
at MySql.Data.MySqlClient.NativeDriver.Authenticate (System.String authMethod, System.Boolean reset) [0x0002a] in <699dc28794d34867bd2008187eb8039c>:0
at MySql.Data.MySqlClient.NativeDriver.Open () [0x0033f] in <699dc28794d34867bd2008187eb8039c>:0
at MySql.Data.MySqlClient.Driver.Open () [0x0000e] in <699dc28794d34867bd2008187eb8039c>:0
at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x0004e] in <699dc28794d34867bd2008187eb8039c>:0
at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0016d] in <699dc28794d34867bd2008187eb8039c>:0
at PlayerXP.PlayerXP.OnEnable () [0x00021] in <cc464d994e5a47c88df91f25374d2f29>:0
推荐答案
感谢 @Bradley Grainger,我的问题解决了.我试过 http://www.nuget.org/packages/MySqlConnector 并且它有效!
Thanks to @Bradley Grainger, my problem is solved. I have tried http://www.nuget.org/packages/MySqlConnector and it works !
这篇关于SQL_ERROR:“MySql.Data.MySqlClient.MySqlConnectAttrs"的类型初始化程序引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL_ERROR:“MySql.Data.MySqlClient.MySqlConnectAttrs"的类型初始化程序引发异常
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01