MySqlConnection =新的MySqlConnection(字符串)不起作用 [英] MySqlConnection = new MySqlConnection(string) not working
问题描述
这是我在Visual Studio中连接到Unity3d的代码:
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.
这是Unity中的错误:
Here is the error in Unity:
KeyNotFoundException:给定的密钥不存在于 字典. System.Collections.Generic.Dictionary`2 [System.String,System.Object] .get_Item (System.String键)(在 /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值)MySql.Data.MySqlClient.MySqlConnection..ctor (System.String connectionString)(包装带检查的远程调用) MySql.Data.MySqlClient.MySqlConnection:.ctor(字符串) mysql.SetupSQLConnection()(位于Assets/mysql.cs:31)fire_rate.Start() (位于Assets/fire_rate.cs:18)
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
@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)
mysql.cs的第31行:
Line 31 of mysql.cs:
connBuilder.Server = "localhost";
fire_rate.cs的第18行:
Line 18 of fire_rate.cs:
GameObject.Find("MySQL").GetComponent<mysql>().SetupSQLConnection();
这篇关于MySqlConnection =新的MySqlConnection(字符串)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!