31

I'm getting extremely long delays (10~30 seconds) in SQL Server Management Studio 2014 when attempting to connect to a SQL Server 2012 instance over TCP using Windows Authentication. This happens when connecting Object Explorer or a new blank query window. Once connected, running queries is fast. The problem does not happen when I connect using SQL Server authentication.

Environment:

  • Windows 7, logged in as a domain user
  • TCP connection via IP address (not hostname)
  • The server is at a remote location connected via VPN
  • No encryption

When I logged into a co-worker's Windows 7 computer with my domain account, and connected to the same SQL Server through the same VPN, there was no delay. When the same co-worker logged into my PC with his own domain account, he experienced the delay. These tests show that the problem is unique to my PC. Also, the problem only appears when connecting to this specific SQL Server and VPN; I can connect to other SQL Servers on the local network via Windows Authentication without any delay.

Things I've tried with no success:

  • Disabled anti-virus and firewall
  • Renamed the "12.0" folder under "%userprofile%\AppData\Roaming\Microsoft\SQL Server Management Studio" to "_12.0" to force SSMS to recreate my user settings.
  • Force Network protocol to TCP rather than <default>. I also tried Named Pipes but my server isn't setup for that.
  • Installed SSMS 2012 and tried that instead of 2014.
  • Disabled IPv6
  • Blackholed crl.microsoft.com to 127.0.0.1 in my etc\hosts file.
  • Disabled the Customer Experience Improvement Program in SSMS, Visual Studio, and Windows.
  • Uninstalled all SQL Server related apps from my PC and reinstalled just 2012.

TCPView clues:

  • Using TCPView, I noticed that when I make a new connection, its state becomes ESTABLISHED right away, but then one or two more connections with the SQL Server are continually attempted and closed with TIME_WAIT. On my co-worker's computer, these connections are ESTABLISHED and solid. So I'm pretty sure this is the source of the timeouts, but what are the connections for, and why do they fail? (I don't have any addons in my SSMS.)

Any ideas?

Update: Intellisense/Autocomplete clue(?):

I noticed that once I finally do connect, Intellisense/Autocomplete doesn't work. Do those require separate connections from SSMS? I tried disabling them, and it didn't seem to resolve the long connection delay.

Jordan Rieger
  • 471
  • 1
  • 6
  • 14

6 Answers6

26

Try running a trace with SQL Profiler while you, and then your coworker, connect to the server.
Select RPC, SQL Statement & PreConnect - Starting/Completed.
Select Save Results To Table option, then compare the 2 tables to find the bottleneck.

Or, since you're connecting by IP, it could be doing a Reverse DNS lookup. If so, add a entry in your hosts file.

d-_-b
  • 1,184
  • 1
  • 12
  • 25
5

What you should check first is your server or client DNS settings

It's not the rare that your SQL Server have the problem connecting to Active Directory. If you try with local Windows account I am sure that you will not have the at issue. It's not unusual that server is configured with public internet DNS and when SQL Server connects to DC to check the credentials and verify it, it will try top contact the public DNS instead of the DNS server of the AD. Since this information is not stored on the public DNS it will fail to verify and this will cause the delay until it manage to contact the proper DNS server or DC via the NTLM

Since you are not experiencing the problem with other SQL Servers, than almost certainly the issue is not related to AD or DC configurations

Fire the IPConfig.exe /all command from the cmd to check the configured DNS servers. You should have only AD's DNS servers configured. Remove all public DNS servers, and leave just AD's DNS servers.

NikolaD
  • 517
  • 6
  • 11
1

I extended C:\Windows\System32\drivers\etc\hosts file by adding line like this:

201.202.203.204     mysqlserver

201.202.203.204 is IP address of your SQL Server.

mysqlserver - any name that you like (you do not have to use it anywhere).

This made my server faster.

Thank to: d-_-b, Jordan, Rieger, felickz, RobbZ

1

Turn off Windows Firewall on your SQL server for the Domain network profile.

  • Start Powershell
  • Run Get-NetFirewallProfile -Profile Domain to check its current state
  • If it's enabled, run: Set-NetFirewallProfile -Profile Domain -Enabled False to turn it off.

If this was it, you can turn it back on later and fine tune your settings. Or, if you're in a safe environment, you can leave it off.

The weird thing is that even if Windows Firewall blocks communication, you will still be able to connect but both the initial handshake and subsequent requests will be incredibly slow. My theory (based on no real evidence) is that in these cases communication falls back on Named Pipes which is a lot slower between remote PCs.

1

I had this problem when we moved to a data centre. IPS had changed and AD has also changed servers.

To resolve, add the server entry on the hosts of the local machine where Management Studio is located.

add the entry on host file on Windows:

xx.xxx.xx.xxx servername.domain

This did a reverse DNS.

1

I had a user using Server Manager Studio with a domain account for authentication, it was slow to open and slow to show the databases. If I used a sql account to connect it was fast. We were connecting by IP and not a name. Someone made a comment in here about a reverse lookup so I edited my hosts file on my pc and did a test. Bam everything worked correctly. I then looked at DNS and low and behold I was missing my PTR for the sql server. I added the PTR, went to the users computer and everything worked fast at that point. This definitely resolved my slowness.