Search code examples
c#sql-serversql-server-2008ado.netsqlconnection

C# Sql Connection can not connect to server


I'm trying to connect SQL server in my virtual machine with following connection string: "Server=qqvm;Database=a_test;Integrated Security=False;User Id=sa;Password=<pass>;Connect Timeout=0"

Firstly I had 'Network connection' exception with inner 'Access Denied' exception with empty stack trace. I did some digging and enabled 'Named Pipes' in SQL Configuration Manager. After that I got this exception:

Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=11281; handshake=1;

However, I'm still able to connect via SQL Management Studio to that server remotely. Any ideas?


Solution

  • Finally in my case specifying IP address instead of qqvm name solved the problem. Still don't know why, though. It worked a week ago.