0

I've been having a connection problem with SQL Server Express 2012, I cannot seem to connect to it from Unity, I keep getting the error message:

SocketException: An existing connection was forcibly closed by the remote host.

Code:

var connectionString: String =
      "Server=Jay\\MSSQLSERVER" +
      "Database=bfcrg;" +
      "User ID=Myuserid;" +
      "Password=mypassword;";

   var dbcon: IDbConnection;

   dbcon = new SqlConnection(connectionString);
   dbcon.Open();

I did do some research & I found out that people have been having this same issue with SQL Server Express 2008 & Unity getting the same SocketException.

As one person had suggested, I uninstalled the server which was installed as a named instance (SQLExpress) & re-installed it as the default instance (MSSQLSERVER). But yeah that didn't fix it.

I have also checked it with the Firewall turned off so no it's nothing to do with the Firewall.

However, I can connect to the Server with the SQL Server Management Studio so the server seems to be working fine I suppose.

So if anyone has any ideas, please let me know!

Cheers! Thanks a lot!

7
  • Connecting to the default instance should not require you to specify an instance name! E.g. you just use server=. or server=(local) (or specify the machine name) without an instance name. Commented Aug 16, 2013 at 4:52
  • There is no semicolon after your Server=Jay\\MSSQLSERVER part. Commented Aug 16, 2013 at 5:08
  • Well, that's exactly what I thought as well, when accessing the default instance that you don't need to specify the instance name, but whenever I leaver the server=machinename or server=localhost or server=127.0.0.1 or my server=localip, it throws another socketException saying No connection could be made because the target machine actively refused it. Commented Aug 16, 2013 at 5:36
  • & Petr, thanks for noticing that! I had it before but I guess I accidentally removed it & now when I try with the semicolon, with the instance name for the server, it says: NotImplementedException: Mono does not support names pipes or shared memory for connecting to SQL Server. Please enable the TCP/IP protocol. What exactly should I do about that?? Commented Aug 16, 2013 at 5:38
  • You should go into SQL server configuration manager, locate the SQL server network configuration section and enable the TCP/IP protocol for your instance, then restart the SQL server service Commented Aug 16, 2013 at 9:28

2 Answers 2

2

Another gotchya is The SQL Browser service being disabled.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

So this is what I figured out in the end, it didn't matter if I had the default instance installed but for some reason I still needed to specify the instance name followed by the machine name in the connection string.

& for the MS SQL Server Express 2012 to accept TCP/IP connections, you should go to the SQL Server Configuration Manager & click on the SQL Server Network Configuration on the left & click on Protocols for your server instance & change the TCP/IP disabled value to enabled & i should work just fine with Unity as long as you have the other necessary DLLs in place.

Thanks a lot everyone for the help!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.