gpt4 book ai didi

c# - MySqlConnection = new MySqlConnection(string) 不起作用

转载 作者:行者123 更新时间:2023-11-29 16:12:25 26 4
gpt4 key购买 nike

这是我在 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: 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)

最佳答案

试试这个

MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

connBuilder.Server = "localhost";
connBuilder.UserID = "root";
connBuilder.Database = "therapygame";
connBuilder.Password = "";
connBuilder.OldGuids = true;

connection = new MySqlConnection(connBuilder.ConnectionString);

关于c# - MySqlConnection = new MySqlConnection(string) 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55145945/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com