mysql new connection,MySqlConnection =新的MySqlConnection(字符串)不起作用

Here is my code in Visual Studio connected to Unity3d:

public void SetupSQLConnection()

{

Debug.Log("Connection Function Started");

if (connection == null)

{

Debug.Log("If connection == null");

try

{

Debug.Log("Try block started");

string connectionString = "Server=localhost;" + "Database=therapygame;" + "UID=root;" + "Password=;";

Debug.Log("string set");

connection = new MySqlConnection(connectionString);

Debug.Log("new MySqlConnection");

connection.Open();

Debug.Log("connection");

}

catch (MySqlException ex)

{

Debug.LogError("MySQL Error: " + ex.ToString());

}

}

}

The Console strings get printed all the way to "string set", but then the rest do not print.

Here is the error in Unity:

KeyNotFoundException: The given key was not present in the

dictionary.

System.Collections.Generic.Dictionary`2[System.String,System.Object].get_Item

(System.String key) (at

/Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)

MySql.Data.MySqlClient.MySqlConnectionStringBuilder.get_Database ()

MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString

(System.String value) MySql.Data.MySqlClient.MySqlConnection..ctor

(System.String connectionString) (wrapper remoting-invoke-with-check)

MySql.Data.MySqlClient.MySqlConnection:.ctor (string)

mysql.SetupSQLConnection () (at Assets/mysql.cs:31) fire_rate.Start ()

(at Assets/fire_rate.cs:18)

解决方案

@Dhansushka Dayawansha

I implemented your change and I received a new error. I'm happy that I got past the first error! I tried looking for solutions to this new error myself to no avail. Here is the console output:

NullReferenceException: Object reference not set to an instance of an object

System.Data.Common.DbConnectionStringBuilder.Remove (System.String keyword)

MySql.Data.MySqlClient.MySqlConnectionStringBuilder.Remove (System.String keyword)

MySql.Data.MySqlClient.MySqlConnectionStringOption.Clean (MySql.Data.MySqlClient.MySqlConnectionStringBuilder builder)

MySql.Data.MySqlClient.MySqlConnectionStringBuilder.SetValue (System.String keyword, System.Object value)

MySql.Data.MySqlClient.MySqlConnectionStringOption.<.ctor>b__0 (MySql.Data.MySqlClient.MySqlConnectionStringBuilder msb, MySql.Data.MySqlClient.MySqlConnectionStringOption sender, System.Object value)

MySql.Data.MySqlClient.MySqlConnectionStringBuilder.set_Item (System.String keyword, System.Object value)

MySql.Data.MySqlClient.MySqlConnectionStringBuilder.set_Server (System.String value)

mysql.SetupSQLConnection () (at Assets/mysql.cs:31)

fire_rate.Start () (at Assets/fire_rate.cs:18)

Line 31 of mysql.cs:

connBuilder.Server = "localhost";

Line 18 of fire_rate.cs:

GameObject.Find("MySQL").GetComponent().SetupSQLConnection();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值