Sql-server – SQL server queries are really slow only on first run

netperformancesql serverwindows 7

Somewhat strange problem… when I start my .NET app for the first time after rebooting my machine, the SQL Server queries are really slow… when I pause the debugger, I notice that it's hanging on getting the response from the query. This only happens when connecting to a remote SQL server (2008)… if I connect to one on my local machine, it's fine. Also, if I restart the app, it works fast, even off the remote SQL server, and subsequent runs are also fine. The only problem is when I connect to a remote SQL server for the first time after rebooting my machine. What's more, I have even noticed this same exact behavior with a 3rd party app (also .NET) that also connects to a remote SQL server.

Another piece of info… this has only started hapenning since I upgraded my machine from XP to Win7 (64 bit). Also, other developers on my team who upgraded to Win7 are seeing the same behavior (both with the app we're developing and the 3rd party .NET app).

(copied from https://stackoverflow.com/questions/2014814/sql-server-queries-are-really-slow-only-on-first-run )

Best Answer

Windows Vista and Windows 7 and SQL Server 2008 do have a different connection method than XP and SQL Server 2008.

When you connect to a Windows 2008 server running SQL 2008 from Vista or Windows 7, Windows tries to negotiate a connection using Security Support Provider Interface [SSPI]. You will occasionally see issues as detailed in http://support.microsoft.com/kb/811889.

My best guess it there is a delay in negotiation of this connection. As you can see in the KB article, there are ways to force the connection to just use standard NTLM negotiation.

I would try to force NTLM by adding SSPI=NTLM to your connection string. If you no longer get the initial speed reduction, this probably points to your problem.

Related Topic