Friends need your help! I'm doing game project as my qualification work in University. I do this in Unity3D. As main part of my project I must use databases in my qualification work. I have created database in SQL Server 2014 Express and trying to use this database in my Unity project. My code is below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Data.SqlClient;
public class GObj : MonoBehaviour {
public void WorkWithDatabase()
{
string connectionstring = @"Data Source=127.0.0.1;Initial Catalog=GameForDiplom;Integrated Security=True;";
SqlConnection Myconnection = new SqlConnection(connectionstring);
Myconnection.Open();
Debug.Log("OPEN SUCCESS!");
using (var cmd = Myconnection.CreateCommand())
{
cmd.CommandText = @"SELECT * FROM [User]";
using (var rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
Debug.Log(rdr["IDuser"] + "\t" + rdr["Nickname"] + "\n");
}
}
}
Myconnection.Close();
Debug.Log("CLOSE SUCCESS!");
}
}
During connection to my database in game i receive this
ERROR: SocketException: The connection is not established, since target machine actively refused the connection request.
Please, I would like to see working code in C# and your settings of SQL 2014 Express which you use. I tried to open TSP port 1433 but I receive this
ERROR: NullReferenceException: Object reference not set to an instance of an object Mono.Data.Tds.Protocol.TdsConnectionPool.GetConnection ()
Friends, i'm not pro programmers as you can see, but i'm trying to be better! Please, help!
Thank you for help, Friends!