- Home /
Question is off-topic or not relevant
Microsoft SQL Server error.
I am writing a game which connects to a local SQL database, however I am getting this error: SocketException: An address incompatible with the requested protocol was used.
System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy)
System.Net.Sockets.Socket+Worker.Connect ()
Rethrow as TdsInternalException: Server does not exist or connection refused.
Mono.Data.Tds.Protocol.TdsComm..ctor (System.String dataSource, Int32 port, Int32 packetSize, Int32 timeout, TdsVersion tdsVersion)
Mono.Data.Tds.Protocol.Tds..ctor (System.String dataSource, Int32 port, Int32 packetSize, Int32 timeout, TdsVersion tdsVersion)
Mono.Data.Tds.Protocol.Tds70..ctor (System.String server, Int32 port, Int32 packetSize, Int32 timeout, TdsVersion version)
Mono.Data.Tds.Protocol.Tds80..ctor (System.String server, Int32 port, Int32 packetSize, Int32 timeout)
Mono.Data.Tds.Protocol.TdsConnectionPoolManager.CreateConnection (Mono.Data.Tds.Protocol.TdsConnectionInfo info)
Mono.Data.Tds.Protocol.TdsConnectionPool.GetConnection ()
System.Data.SqlClient.SqlConnection.Open ()
Rethrow as SqlException: Server does not exist or connection refused.
System.Data.SqlClient.SqlConnection.Open ()
PlayerData.AddPlayer (System.String playerName, Int32 points) (at Assets/Scripts/Database/PlayerData.cs:46)
PlayerData.Start () (at Assets/Scripts/Database/PlayerData.cs:18)
The code which is triggering this error is:
public void AddPlayer(string playerName, int points)
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO users (userName, points) VALUES('" + playerName + "', '" + points + "')", conn);
cmd.ExecuteNonQuery();
Debug.Log("Added Player");
conn.Close();
}
}
The only 'solutions' that seem to of worked for people is enabling TCP/IP in the server settings which I have done and opening the SQL servers ports on the firewall which I have also done. Any help would be greatly appreciated, Aaron.
I'm going to have to close this since the problem has nothing to do with Unity, but I'll recommend a few things: One, StackOverflow has a lot of experts in this subject matter. Two, nothing in that code requires Unity, so try making a unit test with it in a new empty console project to help debug. Three, try to connect with the exact same settings from the same computer using a SQL client (like HeidiSQL) to diagnose connection problems.