- Home /
MySql SocketException: The attempt to establish a connection was unsuccessful, because the desired response was not received from another computer in the required time, or an already established connection was terminated
Hello, I'm studying Mysql connection to unity for myself, I wrote the code, but it doesn't work and gives an error, I can't solve it in any way.
SocketException: The attempt to establish a connection was unsuccessful, because the desired response was not received from another computer in the required time, or an already established connection was terminated due to an incorrect response from an already connected computer.
System.Net.Sockets.Socket.Receive (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags) (at <0463b2ef957545c0a51b42f372cd4fbb>:0)
System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 size) (at <0463b2ef957545c0a51b42f372cd4fbb>:0)
Rethrow as IOException: Unable to read data from the transport connection: The attempt to establish a connection was unsuccessful, because the desired response was not received from another computer in the required time, or an already established connection was terminated due to an incorrect response from an already connected computer.
Code:
using UnityEngine;
using MySql.Data.MySqlClient;
public class SQLScrip : MonoBehaviour
{
string constr = "Server=127.0.0.1;Port=3306;User=root;Password=Password;Database=Games;CharSet=utf8";
public Data Data;
public void BaseData()
{
MySqlConnection con = new MySqlConnection(constr);
MySqlCommand cmd = new MySqlCommand("select * from games.table;", con);
con.Open();
Debug.Log(con.State);
MySqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Data.id = (int)reader["id"];
Data.Money = (int)reader["Money"];
}
}
reader.Close();
cmd.Connection.Close();
cmd.Dispose();
con.Close();
Debug.Log(con.State);
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
MySQL Funktionen Hilfe 1 Answer
Call single function in php from c#? 1 Answer
How to use MySQL.Data dll in Unity 0 Answers