MySql连接。值不能为空。参数名称:类型

时间:2018-06-04 05:34:49

标签: c# android mysql xamarin

当我在下面运行我的代码时,我在运行时收到此错误:

  

值不能为空。参数名称:类型

以下是完整的例外情况:

MySql.Data.MySqlClient.MySqlException: Unable to create plugin for authentication method 'mysql_native_password'. 
Please see inner exception for details. --->
System.ArgumentNullException: Value cannot be null.
Parameter name: type
   at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00006] in /Users/builder/data/lanes/3511/77cb8568/source/mono/mcs/class/referencesource/mscorlib/system/activator.cs:192 
   at System.Activator.CreateInstance (System.Type type) [0x00000] in /Users/builder/data/lanes/3511/77cb8568/source/mono/mcs/class/referencesource/mscorlib/system/activator.cs:134 
   at MySql.Data.MySqlClient.Authentication.AuthenticationPluginManager.CreatePlugin (System.String method) [0x00019] in <4adf5733b5f24682b339d246b115a2af>:0 
    --- End of inner exception stack trace ---
   at MySql.Data.MySqlClient.Authentication.AuthenticationPluginManager.CreatePlugin (System.String method) [0x0003c] in <4adf5733b5f24682b339d246b115a2af>:0 
   at MySql.Data.MySqlClient.Authentication.AuthenticationPluginManager.GetPlugin (System.String method) [0x0001e] in <4adf5733b5f24682b339d246b115a2af>:0 
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.GetPlugin (System.String method, MySql.Data.MySqlClient.NativeDriver driver, System.Byte[] authData) [0x0001f] in <4adf5733b5f24682b339d246b115a2af>:0 
   at MySql.Data.MySqlClient.NativeDriver.Authenticate (System.String authMethod, System.Boolean reset) [0x00029] in <4adf5733b5f24682b339d246b115a2af>:0 
   at MySql.Data.MySqlClient.NativeDriver.Open () [0x00223] in <4adf5733b5f24682b339d246b115a2af>:0 
   at MySql.Data.MySqlClient.Driver.Open () [0x0000b] in <4adf5733b5f24682b339d246b115a2af>:0 
   at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00027] in <4adf5733b5f24682b339d246b115a2af>:0 

打开连接时出错。
这是我的代码:

public string connString()
{
    MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
    builder.Server = "localhost";
    builder.Port = 3306;
    builder.UserID = "root";
    builder.Password = "root1234";
    builder.Database = "tips-db";
    return builder.ToString();
}

public bool Connect()
{
    conn = new MySqlConnection();
    conn.ConnectionString = connString();
    try
    {
        conn.Open();
    }
    catch (Exception e)
    {
        Toast.MakeText(Application.Context, e.InnerException.Message, ToastLength.Long).Show();
        conn.Close();
        return false;
    }
    conn.Close();
    return true;
}

0 个答案:

没有答案