SQL ServerPostgreSQLMySQL

"A network-related or instance-specific error occurred"

The client never even got a response from SQL Server — this is a connectivity problem, not a credentials problem, and the fix is a checklist, not a query.

  • SQL Server: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (usually followed by (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) or error: 53)
  • PostgreSQL: could not connect to server: Connection refused — is the server running on host "..." and accepting TCP/IP connections on port 5432?
  • MySQL: ERROR 2003 (HY000): Can't connect to MySQL server on 'host' (111)

Like Login failed for user, this is a connection-layer error, not a query error — nothing here runs in the playground. The two are easy to confuse but mean opposite things: this one means SQL Server was never reached; 18456 means it was reached and rejected the credentials.

Work through it as a checklist, in this order

1. Is SQL Server actually running, and on the instance name you used? A named instance (SERVER\SQLEXPRESS) is not the same as the default instance (SERVER) — connecting to the wrong one produces exactly this error, not a more specific "wrong instance name" message.

2. Is TCP/IP enabled for the instance? Named Pipes and Shared Memory work for same-machine connections; a remote client needs TCP/IP specifically enabled in SQL Server Configuration Manager → SQL Server Network Configuration → Protocols. This is disabled by default on a fresh install in some editions.

3. Is the SQL Server Browser service running (named instances only)? A named instance listens on a dynamic port by default. The Browser service is what tells a connecting client which port to use — if it's stopped, clients using the instance name alone can't find it even though the database engine itself is up and listening fine.

4. Is a firewall blocking the port? Default instance: TCP 1433. Named instances: a dynamic port (check SQL Server Configuration Manager → TCP/IP → IP Addresses → IPAll → TCP Dynamic Ports), plus UDP 1434 for the Browser service to answer discovery requests. A firewall silently dropping these produces this exact client-side message with no server-side log entry at all — nothing reached the server to log.

5. Is remote access even enabled on the instance? SELECT @@SERVERNAME, SERVERPROPERTY('IsIntegratedSecurityOnly'); run locally on the server (via RDP or console) confirms the instance is up; if remote clients still can't connect, check Server Properties → Connections → Allow remote connections to this server is checked.

6. Is the connection string's hostname/port actually correct? A typo'd server name, a port override that doesn't match what's actually configured, or localhost used from a different machine than the one running SQL Server, all produce this same message.

The error 40 vs. error 53 distinction

The parenthetical at the end of the message narrows it slightly:

  • Error 40 — the client found the server but couldn't complete the Named Pipes/TCP handshake (steps 2-4 above).
  • Error 53 — the client couldn't even locate the server at the network level (hostname doesn't resolve, wrong IP, or it's genuinely unreachable — check step 6, and that the two machines can reach each other at all, e.g. via ping or Test-NetConnection -Port 1433).

Can't demonstrate this in the playground

This is purely a network/service-configuration problem — there's no server process, port, or firewall involved in the in-browser SQLite sandbox here at all. Reproduce it by pointing a client at a real SQL Server instance with TCP/IP disabled, or behind a firewall blocking the relevant port, and work through the checklist above against it.

  • Login failed for user — the error that happens after this one succeeds, when the credentials themselves are wrong.
  • Transactions — what a successful connection lets a session do next.