Error at database connection : SocketException: An address incompatible with the requested protocol was used. How do I solve it?

Hello everyone!

I’m pretty much a newbie in unity projects. Now I have to make a login application as a part of a school project. The already registered user’s username and password is stored in an Sql Express database.

I have an error, and I can’t get a solution for it, although I read a lot on the internet about the respective error. The error is the following:

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 ()
allMenu.loginFunction () (at Assets/Menu/Scripts/allMenu.cs:48)
allMenu.loginGUI (Int32 id) (at Assets/Menu/Scripts/allMenu.cs:34)
UnityEngine.GUI.CallWindowDelegate (UnityEngine.WindowFunction func, Int32 id, UnityEngine.GUISkin _skin, Int32 forceRect, Single width, Single height, UnityEngine.GUIStyle style) (at C:/buildslave/unity/build/Runtime/IMGUI/Managed/GUI.cs:1958)

And it throws at this part of the code:

SqlConnection myCon = new SqlConnection(“Data Source=DESKTOP-4GO8S5E\SQLEXPRESS;Initial
Catalog=fluffydb;Integrated Security=True”);
myCon.Open();

The cursor goes to the end of the Open() function, when I doubleclick on the error.

The same code runs in a VisualStudio c# Console Application, and gets the data what I want.

Please help :smiley:

Here is the whole code regarding to the database connection if it is needed.

SqlConnection myCon = new SqlConnection(“Data Source=DESKTOP-4GO8S5E\SQLEXPRESS;Initial Catalog=fluffydb;Integrated Security=True”);
myCon.Open();
DataTable player = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(“SELECT * FROM player WHERE player.name=” + username, myCon);
adapter.Fill(player);
foreach (DataRow dr in player.Rows)
{
if (dr[“password”] == password)
{
print(“logged in”);
}
else print(“wrong username or password”);
}