Resolve Error 40: Could Not Open a Connection to SQL Server


When we try to connect to the SQL Server, many times we get an Error as Provider: Named Pipes Provider, Error: 40 – could not open a connection to SQL server.

The reasons for getting this error are.

  • This is due to a failure in connecting to the server instance we are using.
  • The wrong default settings.
  • SQL Server does not have permission to allow remote connection.
  • Due to firewall settings.

Follow the below-given solutions to resolve these issues.

1. SQL Server instance is not running

Go to the Services option, and click on SQL Server installed in your system; I have an SQL Server instance installed with the name: MSSQLSERVER. If it is in not Started Status, then start it by right-clicking on it and clicking on the START option.

Services Start

2. Make sure that TCP/IP is enabled

To make it enable, follow the steps: Click on Configuration Manager of SQL Server.


Now you can check the TCP/IP port status as Enabled or Disabled. You need to make it Enable and click on status to change port Properties.


Now fill Default Port no 1433 and click on the OK button.


3. Allow Remote Connections to be enabled under Connections in SQL Server Properties

Follow the below-given steps to enable it.

First, open SQL Management Studio, then right-click on the server name and click on the server Properties.


In the Server Properties under the Connections Options, you need to check the box Allow remote connections to this server and then click on the OK button.

4. Allow SQL Server in Firewall Settings

You need to add a Windows Firewall exception on the server for SQL TCP ports 1433 and 1434 so that SQL Server will run.

Go to Control Panel, then System and Security, or directly search it on your system as Windows Firewall. In this, click on Firewall. Here, you can see the Action tab as Allow for Firewall. You can change it through SQL Server Properties to allow or block it. As given in the below image.


Similar Articles