How Can I Read the Data From mySql in Unity??
Hello. I'm Unity Beginner...
Recently I got some project from my friend. He request me to read some datas from his DB(MySql, HeidiSql)
I made some code but it doesn't work.
Here is my code.
======================================== using UnityEngine; using UnityEngine.UI;
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 DevManager : MonoBehaviour {
static DevManager _instance;
public static DevManager Instance
{
get { return _instance; }
}
string constr = "Server=xxx;" +
"Port=xxx;" +
"Database=xxx;" +
"Uid=xxx;" +
"Pwd=xxx;" +
"CharSet=utf8;";
MySqlConnection con = null;
MySqlCommand cmd = null;
void Awake()
{
//sqlConnect();
}
void Update()
{
//selsql("SELECT DEVNUM FROM TBS WHERE ID = 1");
//selsql();
using(con = new MySqlConnectionconstr
{
con.Open();
string sql = "SELECT DEVNUM FROM TBS WHERE ID = 1;";
cmd = new MySqlCommand(sql, con);
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Debug.Log(rdr["DEVNUM"]);
}
rdr.Close();
}
}
============================
The error is as follows.
KeyNotFoundException: The given key was not present in the dictionary. System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at :0) MySql.Data.MySqlClient.CharSetMap.GetChararcterSet (MySql.Data.Common.DBVersion version, System.String CharSetName) (at :0) MySql.Data.MySqlClient.NativeDriver.GetFieldMetaData41 () (at :0) MySql.Data.MySqlClient.NativeDriver.GetFieldMetaData () (at :0) MySql.Data.MySqlClient.NativeDriver.ReadColumnMetadata (System.Int32 count) (at :0) MySql.Data.MySqlClient.MySqlDataReader.NextResult () (at :0) MySql.Data.MySqlClient.MySqlCommand.ExecuteReader (System.Data.CommandBehavior behavior) (at :0) MySql.Data.MySqlClient.MySqlCommand.ExecuteReader () (at :0) (wrapper remoting-invoke-with-check) MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() DevManager.Update () (at Assets/Script/DevManager.cs:64)
Since I'm not an expert in Unity, so I don't know the details of the error, but I think there was an error in line 64. : ExecuteReader
I found some example from forum, They didn't work at all either. Please tell me How to solve this problem.
Your answer

Follow this Question
Related Questions
MYSQL & Unity, Where to get the libraries to reference? 2 Answers
MySQL Web Player 0 Answers
WebGL Build strange exception 0 Answers
C# safe connect to MySQL database. Download and upload data via PHP script. 1 Answer
Unity does not read floats from MySQL 0 Answers