- Home /
SocketException: No connection could be made because the target machine actively refused it.
I'm trying to connect to a database but I continue getting the error shown in the title. I have my backend services separated from the Unity client side and have the backend dll added into the Assets folder. I know that I'm hitting my backend methods because I'm logging a message when I get into the method. I have my SQL Server running locally with the authentication being Windows Authentication. So my question is, why can I not hit the database? I'm using the latest version of Unity 2018.3.12f1.
Here's my client side code that triggers on a button click.
 public class User : MonoBehaviour
     {
         public void Login(){
             var meh = new DBStuff();
             meh.Login();
         }
 }
Here's my backend service that makes the db connection
 public class DBStuff
 {
     private const string _connectionString = "Data Source=localhost;Initial Catalog=Players;Integrated Security=True;Pooling=False";
     SqlConnection _db;
     public void Login() {
         //Hit's the loginservice
         Debug.Log("Here");
         _db = new SqlConnection(_connectionString);
         _db.Open();
     }
 }
Can anyone shed any light on why I'm getting this error and how I might go about fixing it? Thanks.
There are many things unclear. Are you actually using a microsoft SQL server? (not $$anonymous$$ySQL or something else). The SqlConnection class is only for $$anonymous$$sSql servers. Generally this error is generated when you either do not have a server / service running on the specified port or if a firewall is blocking the connection. So make sure your server is actually running on the default port (1433) and no firewall is blocking the connection.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                