Cannot Connect to SQL Server: The Checks in the Order That Finds It

Read the error number before you touch anything. 53, 40, 10061 and 26 mean nothing answered, so the problem is the service, the port, the firewall or the name, in that order. 18456, 916, 17806 and the pre-login handshake error mean something answered and then refused you, so the network is fine and the problem is the login, the certificate or Kerberos. The two families have nothing in common and the checks below are in the order that finds the fault fastest.

Which Error Do You Have?

Every “cannot connect” message ends in a number, and the number says which half of this page you need. Find yours first.

NumberWhat the client saysWhat it meansStart at
53The network path was not foundThe name did not resolve, or nothing is reachable at that addressStep 1
40 / 10061Could not open a connection to SQL Server; target machine actively refused itThe machine answered, nothing is listening on that portStep 2
26Error locating server/instance specifiedA named instance that the SQL Browser could not resolveStep 4
233No process is on the other end of the pipeConnected, then dropped before login: protocol or encryptionStep 5
pre-login handshakeA connection was successfully established, but then an error occurredTCP is fine, TLS is notStep 5
17806SSPI handshake failed, cannot generate SSPI contextWindows authentication could not get a ticketStep 5
18456Login failed for userEverything up to authentication workedStep 6
916The server principal is not able to access the databaseLogged in, no access to that databaseStep 6

If the number is 53, 40, 10061 or 26, do not check the password. Nothing has asked for it yet. The full entry for the most common one is error 53 and the named pipes errors, and this page is the route through all of them.


STEP1

Step 1: Is the Service Running, and Which Instance Is It?

On the server, or from any machine that can reach it over Windows, confirm the SQL Server service for the instance you are connecting to is actually running, and note whether it is a default instance or a named one, because everything after this depends on that. Get Services Information lists every SQL Server service on the box with its state, start mode and account in one run, which also catches the case where the Agent is up and the engine is not, or a service account changed at the last password rotation.

If the service is stopped, start it and read the error log before doing anything else. If it is running, move on: a running service with nobody able to connect is the normal shape of this incident.


STEP2

Step 2: Is SQL Server Listening on TCP, and on Which Port?

A default instance listens on 1433. A named instance listens on a dynamic port unless somebody fixed it, and on a fresh install TCP/IP may not be enabled at all, which is the single most common cause of “works on the server, fails from anywhere else”. SQL Server Default Ports explains the port model and how to find the port an instance actually chose; Enabling TCP Connections in SQL Server is the fix when the protocol is off.

Two things people get wrong here. Enabling TCP/IP in Configuration Manager does nothing until the SQL Server service is restarted, so the change that “did not work” usually did, it just has not taken effect. And the port SQL Server thinks it is on is not proof anything is bound to it from the outside, which is what the next step checks. On the server, How to Check Listening Ports on Windows shows what is genuinely bound and by which process.


STEP3

Step 3: Can the Client Reach That Port?

From the machine that cannot connect, test the port itself rather than the SQL Server connection. Testing Remote Server Port Connectivity with PowerShell does it with Test-NetConnection and reads the result for you: a closed port when Step 2 says SQL Server is listening is a firewall, on the server, on the client, or somewhere between. If the address you are testing is not the one SQL Server is on, How to Get the SQL Server IP Address tells you which address and port an existing session actually connected to, which settles most arguments about DNS and aliases.


STEP4

Step 4: Named Instances, Error 26 and the SQL Browser

Error 26 is specific to named instances. The client asks the SQL Browser service on UDP 1434 which port SERVER\INSTANCE is using, and if the Browser is stopped, blocked or absent, the client never learns the port and reports that it could not locate the instance. Three fixes, any one of which works: start the SQL Browser and allow UDP 1434 through the firewall, fix the instance to a static port and open that, or connect as SERVER,port and bypass the Browser altogether. The port side of that is covered in SQL Server Default Ports.


STEP5

Step 5: It Answered, Then Dropped You: Certificates, Handshakes and Kerberos

From here the network is not the problem. Something on the server accepted the TCP connection and then refused to carry on, and the message tells you which layer.

The certificate chain was issued by an authority that is not trusted. Newer drivers and SSMS releases encrypt by default and validate the server certificate, so a connection that worked last month fails after an upgrade. SSMS Certificate Chain Not Trusted is the fix and the reason, and Check SQL Server Connection Encryption and Protocol shows what the server is actually negotiating so you can decide whether to trust the certificate or give the server a proper one.

A connection was successfully established, but then an error occurred during the pre-login handshake. Same layer, different symptom: TCP connected, TLS did not. The pre-login handshake error walks through the protocol and cipher mismatches that cause it, and why checking the password is the wrong first move.

Cannot generate SSPI context, SSPI handshake failed (17806). Windows authentication could not obtain a Kerberos ticket, almost always a missing or duplicate SPN or a clock or domain trust problem. SSPI Handshake Failed covers the diagnosis, and Kerberos vs NTLM in SQL Server explains which scheme your connections are really using and why it matters.


STEP6

Step 6: You Reached the Server and It Said No

Login failed for user (18456) is the end of the connection story and the start of a security one: the state number in the error log says exactly why, and the post decodes every state. If the login worked and one database refuses you, that is error 916, a database user problem rather than a connection problem, and the connection was fine all along.


Frequently Asked Questions

It works on the server but not from my machine. Why?
Local connections use Shared Memory, which needs no port and no firewall rule, so a server with TCP/IP disabled or a firewall blocking 1433 looks perfectly healthy when you test it from the console. Steps 2 and 3 are the ones that find it: enable TCP/IP, restart the service, then test the port from the client.
I enabled TCP/IP and it still does not work.
The protocol change only takes effect when the SQL Server service restarts. Restart it, then confirm with the listening-ports check in Step 2 that something is bound to the port before testing from outside again.
What is the difference between error 26 and error 40?
26 means the client could not even work out which port to use, which only happens with named instances and the SQL Browser. 40 (and 10061 underneath it) means the client knew the address and port and nothing was listening there. 26 is a Browser or naming problem, 40 is a service, protocol or firewall problem.
Should I just tick Trust Server Certificate?
For a lab or a dev box, yes, and get on with your day. For production it means the client stops checking who it is talking to, so the better fix is a certificate the client trusts. Both options and the reasoning are in the certificate chain post linked in Step 5.

Related

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *