Home » SQL Server Error 40 Could not open connection Named Pipes Provider, error: 40

SQL Server Error 40 Could not open connection Named Pipes Provider, error: 40

sql server DBA 999

Error Details:

SQL Server Error 40 Could not open connection Named Pipes Provider, error: 40 or sql server error 40 named pipes provider and other forms of error below

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 1326)

or

ERROR: (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error:) An error has occurred while establishing a connection to the server. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 5)

or

System.Data.SqlClient.SqlException: '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. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'

or

A network-related error 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. (provider: TCP Provider, error: 0 - No such host is known.) (Microsoft SQL Server, Error: 11001)

The SQL Server Error 40 can be either Named Pipes connections or TCP/IP connections related errors. we look at what may be causes to these errors and how to resolve.

Solutions for SQL Server Error 40:

1. First thing to check if your slash is backslash not the other one. This happens to many developers and new DBA’s for errors sql server error 40 could not open a connection, sql server error 4060 cannot open database and
sql server error 40 error 2. Also for errors like a network-related or instance-specific error occurred while establishing a connection to sql server ornamed pipes provider: could not open a connection to sql server (53)

SERVER\INSTANCENAME is correct with it’s a backslash (\).

2.Make sure SQL Server Service is running for named pipes provider could not open a connection to sql server error 2 or a network-related or instance-specific error in sql server 2014 error: 40
3.Make Sure TCP and Named pipes are enabled for named pipes provider could not open a connection to sql server error 2 or a network-related or instance-specific error in sql server 2014 error: 40

SQL Server Error 40 Could not open connection Named Pipes Provider, error: 40
4.If a named instance, make sure SQL Server browser service is running
5. Make sure SQL Server is configured to allow remote connections in Server properties in SSMS by right click on Server name in SSMS and go to properties and check under Connections to see if Remote access is ticked (enabled) or not.
exec sp_configure "remote access", 1

6. Examine the SQL Server error log for messages confirming that SQL is listening on the expected network interfaces and ports. Below listed way to find sql error log location.
7.Test server connectivity with PING from the client machine
8.Test port connectivity using TELNET or PowerShell to the server and port (from step 4) from the client machine for a network-related or instance-specific error occurred while establishing a connection to sql server or for named pipes provider: could not open a connection to sql server (53)

  •  TELNET 1433
  • PowerShell commands for checking if port is open for remote SQL Server connection for errors sql server error 40 could not open a connection, sql server error 4060 cannot open database and sql server error 40 error 2.
Test-NetConnection -ComputerName SQLServername -Port 1433
TNC -ComputerName SQLServername -Port 1433

7. Check firewall settings to see if ports are open for a network-related or instance-specific error in sql server 2014 error: 40

8. Check if the Service Principal Name is registered

If you can connect to SQL Server by physically logging on to the server but not from a client computer, check the SPN by running the query below in a query window to check SQL Error log to see the error.

EXEC xp_readerrorlog 0,1,"could not register the Service Principal Name",Null

9. Make sure DNS is working that is if it resolves using an IP address to SQL Server name, you can add the SQL Server machine into /etc/host file manually if DNS is not reachable or working. To add the entry in the /host file type %SystemRoot%\system32\drivers\etc\ in the run window and double click / open the host file using Notepad. In the below image I added IP address 192.100.100.1 with a machine name of TESTSQLDB. Now it should be able to resolve the machine name  to IP address to connect to the SQL Server. Verify with Ping TESTSQLDB on CMD prompt.

10. Make sure we are using the correct instance name that is for default instance, Servername can be used for instance name. For named instance such as sqlexpress, you need to specify the instancename like Servername\instancename.

11.You may check whether TCP/Named pipes setting is enabled on SQL Server if you use SQL Server Developer Edition. The default setting of TCP/Named pipes is disable on SQL Server Developer Edition. You can change this setting using SQL Server configuration manager. And also you may check firewall configured for incoming connections on Windows OS.

Reading sql server error log location and Errors

Identifying SQL Server Error Log File used by SQL Server Database Engine can be done by reading SQL Server Error Logs. DBA can execute the XP_READERRORLOG extended stored procedure to read the SQL Server Error Log and search for its location used by the instance of SQL Server.

USE master
Go
xp_readerrorlog 0, 1, N'Logging SQL Server messages in file', NULL, NULL, N'asc'
Go

The parameters for XP_READERRRORLOG are:
1. Value of error log file we would like to read. values are 0 = current, 1 = last one before current, 2 = second last before current etc…
2. Log file type:- 1 or NULL = error log, 2 = SQL Agent log
3. Search string 1:- String one you want to search for
4. Search string 2:- String two you want to search for to further refine the results
5. start time for Search
6. end time for search
7. Sort order for search results:- N’asc’ = ascending, N’desc’ = descending

Conclusion:

I’ve done my best to include named pipes provider, error: 40 related all of the solutions mainly for  sql server error 40 named pipes provider, sql server error 40 could not open a connection, sql server error 4060 cannot open database, sql server error 40 error 2 etc.. but if I’ve missed any, please let me know and I’ll gladly include them.

Leave a Reply

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