C# Unity3D连接到MySQL错误
我试图让Unity客户端建立到MySQL服务器的连接,这纯粹是为了读取。我在建立连接时出错 我的代码:C# Unity3D连接到MySQL错误,c#,mysql,dictionary,unity3d,monodevelop,C#,Mysql,Dictionary,Unity3d,Monodevelop,我试图让Unity客户端建立到MySQL服务器的连接,这纯粹是为了读取。我在建立连接时出错 我的代码: using UnityEngine; using System; using System.Data; using System.Text; using System.Collections; using System.Collections.Generic; using System.Security.Cryptography; using MySql.Data; using MySql.D
using UnityEngine;
using System;
using System.Data;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using MySql.Data;
using MySql.Data.MySqlClient;
public class DatabaseHandler : MonoBehaviour {
public string host, database, user, password;
public bool pooling = true;
private string connectionString;
private MySqlConnection con = null;
private MySqlCommand cmd = null;
private MySqlDataReader rdr = null;
private MD5 _md5Hash;
void Awake() {
DontDestroyOnLoad(this.gameObject);
connectionString = "Server="+host+";Database="+database+";User ID="+user+";Password="+password+";Pooling=";
if (pooling){
connectionString += "true;";
} else {
connectionString += "false;";
}
try {
con = new MySqlConnection(connectionString);
con.Open(); // THIS is line 47 in the error
Debug.Log ("Mysql State: " + con.State);
} catch (Exception e) {
Debug.Log (e); // THIS is line 51 in the error
}
}
}
错误:
System.Collections.Generic.KeyNotFoundException:未找到给定的密钥
出现在字典里。在
System.Collections.Generic.Dictionary`2[System.String,MySql.Data.MySqlClient.CharacterSet].get\u项
(System.String键)[0x000a2]输入
/Users/builduser/buildslave/mono运行时和classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150
位于MySql.Data.MySqlClient.CharSetMap.GetCharacterSet(DBVersion
0中的版本,System.String CharSetName)[0x00000]
在MySql.Data.MySqlClient.CharSetMap.GetEncoding(DBVersion)中,
System.String CharSetName)[0x00000]位于:0处
MySql.Data.MySqlClient.Driver.Configure
中的(MySql.Data.MySqlClient.MySqlConnection连接)[0x00000]
:0位于MySql.Data.MySqlClient.MySqlConnection.Open
()[0x00000]英寸:0处(包装器
远程处理(通过检查调用)
MySql.Data.MySqlClient.MySqlConnection:Open()位于
DatabaseHandler.Awake()[0x0007a]位于/Users/ThaMacPro/Desktop/Unity中
Projects/youtubeMySQL/Assets/Scripts/DatabaseHandler.cs:47
调试:日志(对象)数据库处理程序:唤醒()(位于
Assets/Scripts/DatabaseHandler.cs:51)
有人能告诉我如何修复这个错误吗
谢谢大家! 解决方案:
必须将字符集添加到连接字符串
谢谢@Roberto!:-) 看起来您提供的连接字符串无效;忘记unity,试试谷歌搜索这个特定的mysql错误。谢谢@Roberto,在搜索了更多特定的关键字后,我发现了这个问题,解决了这个问题。您愿意提供该链接作为答案吗?我会把它标记为答案@Robertohaha这是我在谷歌上发表评论的答案,但我没有提到UTF,因为我认为这不是问题所在。无论如何,我认为你写下答案并做标记是公平的。我遇到了更多的问题,与大多数人没有遇到的相同类型的错误,所以我最终为我的MySQL数据库使用了不同的主机(rackspace)。没有问题了。