C# SQL#U错误:';MySql.Data.MySqlClient.MySqlConnectAttrs';抛出异常
我的C#代码和MySQL有一个错误。 你能帮我解决吗 这是我的密码:C# SQL#U错误:';MySql.Data.MySqlClient.MySqlConnectAttrs';抛出异常,c#,mysql,mono,C#,Mysql,Mono,我的C#代码和MySQL有一个错误。 你能帮我解决吗 这是我的密码: try { using (MySqlConnection dbcon = new MySqlConnection(SQLConnectionString)) { dbcon.Open(); // ERROR HERE string sql = "SELECT * FROM scp_patreons"; MySqlCommand command = new
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 + "\n" + 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
SQL\u错误:“MySql.Data.MySqlClient.MySqlConnectAttrs”的类型初始值设定项引发异常。
at(wrapper managed to native)System.Object.\uuIcall\uwrapper\uMono\uGeneric\uClass\uInit(intptr)
在0中的MySql.Data.MySqlClient.NativeDriver.SetConnectAttrs()[0x00018]处
在:0中的MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(System.Boolean reset)[0x00080]处
在:0中的MySql.Data.MySqlClient.NativeDriver.Authenticate(System.String authMethod,System.Boolean reset)[0x0002a]处
位于:0中的MySql.Data.MySqlClient.NativeDriver.Open()[0x0033f]
在:0中的MySql.Data.MySqlClient.Driver.Open()[0x0000e]处
在:0中的MySql.Data.MySqlClient.Driver.Create(MySql.Data.MySqlClient.MySqlConnectionStringBuilder设置)[0x0004e]处
位于:0中的MySql.Data.MySqlClient.MySqlConnection.Open()[0x0016d]
在0中的PlayerXP.PlayerXP.OnEnable()[0x00021]处
我正在运行5.7.25-MySQL社区服务器(GPL)服务器:带有UNIX套接字的本地主机 协议版本:10
用户:root@localhost
服务器字符:UTF-8 Unicode(utf8)
Mono JIT编译器版本5.18.0.268
连接器/网络8.0.15
我使用Debian9.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
System.TypeInitializationException:'MySql.Data.MySqlClient.MySqlConnectAttrs'的类型初始值设定项引发异常。-->System.IO.FileNotFoundException:无法加载文件或程序集“System.Management,版本=4.0.0.0,区域性=中性,PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。
在0中的MySql.Data.MySqlClient.MySqlConnectAttrs..cctor()[0x0000f]处
---内部异常堆栈跟踪的结束---
at(wrapper managed to native)System.Object.\uuIcall\uwrapper\uMono\uGeneric\uClass\uInit(intptr)
在0中的MySql.Data.MySqlClient.NativeDriver.SetConnectAttrs()[0x00018]处
在:0中的MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(System.Boolean reset)[0x00080]处
在:0中的MySql.Data.MySqlClient.NativeDriver.Authenticate(System.String authMethod,System.Boolean reset)[0x0002a]处
位于:0中的MySql.Data.MySqlClient.NativeDriver.Open()[0x0033f]
在:0中的MySql.Data.MySqlClient.Driver.Open()[0x0000e]处
在:0中的MySql.Data.MySqlClient.Driver.Create(MySql.Data.MySqlClient.MySqlConnectionStringBuilder设置)[0x0004e]处
位于:0中的MySql.Data.MySqlClient.MySqlConnection.Open()[0x0016d]
在0中的PlayerXP.PlayerXP.OnEnable()[0x00021]处
多亏了,我的问题解决了。我已经试过了,而且很有效 密码错误?否@TheImpler这是正确的密码。永远不要执行“SQL\U错误:”+ex.Message+“\n”+ex.StackTrace。改为执行ex.ToString(),看看是否可以获得一些有用的信息OK@Steve我用新的错误消息修改了我的帖子。可能是Connector/NET与Mono不完全兼容。尝试具有更好跨平台支持的OSS替代方案。