Question by
Arcosha · Dec 19, 2017 at 05:39 PM ·
c#connectionsqlsqldatabase
MSSQL 2014 Connection and Socket Exception
Hello friends! Need your help!
I created database in MSSQLEXPRESS 2014 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 (In English-> 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 MSSQL EXPRESS 2014 which you use.
Thank you for help, Friends!
error.png
(4.0 kB)
Comment