SQL Server Error 40: A network-related or instance-specific error occurred while establishing a connection to SQL Server.
Today, a user has raised a request to fix an error (Microsoft SQL Server Error 40 – Could not open a connection to SQL Server or Microsoft SQL Server, Error 2) he was getting while establishing the database connection. The error details are given below.
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) (Microsoft SQL Server, Error: 2)
Below is the screenshot of above Microsoft SQL Server error 40.
Sometimes, we get same error under below error text.
An error has occurred while establishing a connection to the server. When connecting to SQL Server, 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) (.Net SqlClient Data Provider)
Microsoft SQL Server Error 40 – Root Cause
We get SQL error 40 because SQL Server did not respond to the client request. This issue occurs due to multiple reasons. I have given all those possible reasons behind Microsoft SQL Server error 40 in below points.
- Server is probably not started and shutdown.
- SQL Server Service is down.
- SQL Server Instance is not accessible due to firewall or any reason.
- Telnet port 1433 or port no on which SQL Server is running. These ports might be blocked.
- TCP/IP or Named Pipes protocol is disabled in SQL Server Configuration Manager.
- Remote Connection is disabled for this SQL Server Instance.
- SQL Server browser service is stopped.
- Wrong SQL Server Instance name while establishing database connection
We need to check and validate multiple factors to rectify Microsoft SQL Server error 40. Check all factors given in below step by step points to fix all possibilities for this error.
- Make sure that database server is up and running fine.
- Make sure SQL Server services are running fine and its accessible.
- Check firewall details. Firewall should open between your client machine and database server.
- Port 1433 and 1434 should be enabled. Telnet both ports to make sure ports are open.
- Make sure to enable TCP/IP and Named Pipes protocols. Launch SQL Server Configuration Manager. Expand SQL Server Network Configuration from left side pane and click on Protocols for MSSQLSERVER. MSSQLSERVER is SQL Server Instance name. Now you will see all protocols in to right side pane. Right click on given protocols and select Enable button to enable both protocols.
- Remote connection must be enabled to connect to databases remotely. Connect to SQL Server Instance in SSMS. Right click on SQL Server instance name in SSMS and choose Properties. You will get Server properties window. Click on Connections from left side pane and tick the check box on Allow remote connections to this server option from right side pane.
- SQL browser service should not be stopped if your security policy allows it. If you have disabled this service to apply hardening then make sure to pass port no along with SQL Server instance name while making database connection.
- Sometimes, we enter wrong server details. Make sure to enter correct SQL Server instance name while making database connection.
- Fix Error 28 – Server doesn’t support requested protocol
- Fix Error 233: How to set user connections server configuration in SQL Server?
- Error 4064: Cannot open user default database. Login failed.
- SQL Server Update Statistics Best Practices - April 15, 2020
- Understanding Hybrid Buffer Pool in SQL Server - December 30, 2018
- Fix:VIEW SERVER STATE permission was denied on object ‘server’, database ‘master’ - August 30, 2018