Please read in the entirety before marking this as duplicate.
In a project that I am debugging I receive a SqlException saying the following:
Additional information: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The wait operation timed out.)
This occurred during a debugging session where the previous session executed only seconds before without problem. Since the initial exception, I am unable to connect to the database server in this project. The exception is thrown on the SqlConnection.Open() method call.
This is not the first time that I have received this. Previously I struggled with it for two weeks eventually initiating a Microsoft support ticket for it. In that instance it turned out the ApplicationName property on the connection string was too long (we were using the fully qualified assembly name) and shortening it alleviated the problem.
This time around, there is
Finally, on a whim, I created a new project whose sole purpose was to connect to this same SQL server. I copied the connection string from the non-working project, into the new project and it connects. Is there some kind of per-project connection caching going on? Something that survives a Clean>Rebuild and a restart of Visual Studio and Windows too?
public SqlConnection OpenSqlConnection(string connectionString)
{
var conn = new SqlConnection(connectionString);
conn.Open();
_connectionString = connectionString;
var sb = new SqlConnectionStringBuilder(_connectionString);
_server = sb.DataSource;
_database = sb.InitialCatalog;
return conn;
}
The connection string that is being passed in is output from a SqlConnectionStringBuilder elsewhere in the application. The connection string is similar to: "Data Source=SERVER;Initial Catalog=DATABASE;Integrated Security=True;Connect Timeout=60"
means that the client application was able to complete the TCP 3-way handshake properly (hence you notice “ A connection was successfully established with the server ”), but during the pre-login handshake, the client application checks with the SQL Server on the TDS protocol version to be used henceforth for the ...
What did the trick for me is increasing the timeout on the connection string, since when connecting by vpn it took to long to establish the connection. You can do this by adding ;connection timeout = value
I got the same error when connecting an application tried to connect to sql server while I was on a vpn.
By default the timeout is set to 15 seconds.
Seems you already have 60secs, maybe you just need more...
Hope it helps!
This problem can be related to a firewall in the middle that is doing SSL inspection.
I Suggest you either try again using another connection not doing SSL inspection, or ask your firewall admin to create an exemption for the source and/or destination you are connecting to,
Cheers!
Try explicitly adding Application Name=MyAppName;
to the connection string. Auto-generated value from the assembly name might exceed some limit.
Check network settings for things like explicitly limited frame size. Reboot router if SQL Server is running on another machine.
Try adding Pooling=False;
to the connection string and checking whether this solves the problem with repeated connections on application restart.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With