- Error number
- 40
- Severity
- 20 (fatal: the connection ends; may indicate a serious problem)
- State
- 0
- Product
- Microsoft SQL Server Database Engine
- Versions
- Any SQL Server version reached from Windows clients through SQL Server client drivers
- Category
- Connectivity
- Last reviewed
- 23 October 2026
On this page
What it means
Error 40 is a client-side error: the Named Pipes provider in the driver could not open the pipe of the SQL Server instance, so no connection was made; the Windows error number after it (53, 2, 5 and so on) says why.
This page covers the client error 40 from the Named Pipes provider of the SQL Server driver. It is not a SQL Server engine message (sys.messages has no message 40). The driver tries the enabled protocols in order; when it ends on Named Pipes and cannot open \\server\pipe\sql\query (or \\server\pipe\MSSQL$INSTANCE\sql\query for a named instance), it reports error 40.
Error 40 by itself only says that the last protocol tried was Named Pipes and it failed. The number that follows carries the cause: SSMS shows it as (Microsoft SQL Server, Error: 53), the Windows code for "the network path was not found" (see error 53); ODBC Driver 18 shows it in square brackets, such as [2], "the system cannot find the file specified", when the machine is reachable but no such pipe exists. Very often TCP/IP failed first and Named Pipes is only the fallback, so fix the TCP path rather than enabling pipes.
Common causes
- The server name is wrong or does not resolve, so the pipe path cannot be reached (Windows error 53).
- The SQL Server service is stopped, or the instance name in the pipe path is wrong (Windows error 2).
- TCP/IP failed or is disabled on the client or server, and the driver fell back to Named Pipes, which is disabled on the server.
- File and printer sharing (SMB, TCP 445) is blocked by a firewall; Named Pipes connections to another machine travel over SMB.
- The Windows user has no permission to log on to the server over the network, which Named Pipes requires (documented by Microsoft).
Diagnose it
Read-only These queries only read metadata and dynamic management views. They do not change data, permissions or configuration, so they are safe to run first.
Which pipes does the instance listen on?
Run on the server. SQL Server writes every pipe it opens to the error log at startup.
EXEC sp_readerrorlog 0, 1, N'provider is ready to accept connection'; Lines such as Server local connection provider is ready to accept connection on [ \\.\pipe\sql\query ]. Only local pipes listed (SQLLocal) means Named Pipes for remote clients is disabled. Compare the pipe name with the one the client uses.
Which protocol do working connections use?
SELECT net_transport, COUNT(*) AS connections
FROM sys.dm_exec_connections
GROUP BY net_transport; TCP rows show TCP/IP works for other clients, pointing at the failing client's name, alias or protocol order. Only Shared memory means nothing remote is connected.
Test TCP explicitly from the client
Run sqlcmd -S tcp:SERVER -E (or tcp:SERVER\INSTANCE). If TCP works, the application was falling back to Named Pipes; fix its server name, alias or client protocol order. If it fails, follow the TCP error instead (10061, 10060 or 26).
How to fix it
Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.
Correct the server name and force TCP
Client or network sideUse the real server and instance name, and prefix it with tcp: so the driver does not fall back to Named Pipes and hide the real TCP error.
sqlcmd -S tcp:SQLPROD01\SALES -E
Start the SQL Server service
Changes configurationCheck the service in SQL Server Configuration Manager or with Get-Service MSSQL* on the server, and start it if it is stopped.
Enable TCP/IP (preferred) or Named Pipes on the server
Changes configurationIn SQL Server Configuration Manager, under SQL Server Network Configuration, enable TCP/IP for the instance. Enable Named Pipes only if a client genuinely needs it. Either change takes effect after a service restart.
Caution: Restarting the SQL Server service disconnects every session; schedule it.
Fix the client alias or protocol order
Client or network sideAn old alias in SQL Server Configuration Manager (Native Client configuration) or in cliconfg.exe can point at a wrong pipe name. Rename or remove it, and keep TCP/IP ahead of Named Pipes in the client protocol order.
Examples
A pipe that does not exist on the machine
Reproduced with sqlcmd and ODBC Driver 18 on 2026-10-23. The machine (.) exists but no instance listens on that pipe, so Windows returns error 2 (file not found) inside the provider message.
sqlcmd -S np:\\.\pipe\cws_nosuch_n5\sql\query -E -C -l 5
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Named Pipes Provider: Could not open a connection to SQL Server [2]. . Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Login timeout expired. Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to np:\\.\pipe\cws_nosuch_n5\sql\query. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
How to prevent it
Use TCP/IP for all remote connections and say so in the connection string (tcp: prefix or Network Library=DBMSSOCN in older providers), so a TCP failure surfaces as a TCP error instead of a misleading Named Pipes error 40.
Keep connection strings and aliases in one managed place, remove stale aliases when servers move, and test with sqlcmd from each application host after network changes.
Common questions
Why does my error mention Named Pipes when I use TCP/IP?
The driver tries enabled protocols in order and reports the last one it tried. If TCP fails first, the Named Pipes fallback fails too and becomes the error you see. Force TCP with the tcp: prefix to see the real cause.
What is the difference between error 40 and error 53?
Error 40 is the provider error (Named Pipes could not open a connection). Error 53 is the Windows reason often shown with it: the network path to the server was not found. Other Windows codes, such as 2 for a missing pipe, can follow error 40 too.
Should I enable Named Pipes to fix error 40?
Usually not. Most applications should use TCP/IP; enabling Named Pipes only hides a TCP problem. Enable it only when a specific client must use it, and open SMB in the firewall for remote pipes.
Learn more on CodeWithSQL
Official documentation
- Fix network-related or instance-specific errors in SQL Server (Microsoft Learn)
- Enable or disable a server network protocol
- Named Pipes connections fail when the user has no permission to log on to Windows
Last technically reviewed 23 October 2026; examples and diagnostics run on SQL Server 2025 (17.0.1145.4), ODBC Driver 18 for SQL Server. Message text checked against the engine's sys.messages catalogue.