【发布时间】:2019-03-13 15:45:32
【问题描述】:
这是我在 Visual Studio 中连接到 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());
}
}
}
控制台字符串一直打印到“字符串集”,但其余部分不打印。
这是 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) (wrapper remoting-invoke-with-check) MySql.Data.MySqlClient.MySqlConnection:.ctor(字符串) mysql.SetupSQLConnection () (at Assets/mysql.cs:31) fire_rate.Start () (在 Assets/fire_rate.cs:18)
【问题讨论】:
-
我怀疑这不是确切的连接字符串(显然你修改了密码)。您是否尝试过
string connectionString = @"....."忽略转义字符? -
这是客户端代码还是服务器端代码,我问这个是因为您不应该在客户端应用程序中公开硬编码的数据库登录信息,因为现有的反编译器和/或反汇编程序