SQL SERVER – FIX : ERROR : (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: )

Regular readers of my blog are aware of the fact that I have written about this subject umpteen times earlier, and every time I have spoken about a new issue related to it. Few days ago, I had redone my local home network. I have LAN setup with wireless router connected with my four computers, two mobile devices, one printer and one VOIP solution. I had also formatted my primary computer and clean installed SQL Server 2008 into it. Yesterday, incidentally, I was sitting in my yard trying to connect SQL Server located in home office and suddenly I stumbled upon the following error. Finding the solution was the most infuriating part as it consumed my precious 10 minutes.

Let us look at few of the common errors received:

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)

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)

I eventually found the resolution to this error on this blog itself; so I was saved from hunting for the solution. I am sure there are a number of developers who had previously fixed this error while installing SQL Server 2008 or SQL Server 2005 but in due course forgot the right solution to this error. This is just a quick refresher. Make sure to bookmark this as you never know when you would need this solution.

Let us check into the steps to resolve this error.

1) SQL Server should be up and running.

Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> SQL Server Services, and check if SQL Server service status is “Running”.

In addition, ensure that your remote server is in the same network. Run “sqlcmd -L” in your command prompt to ascertain if your server is included in your network list. You can even find tutorial for the same here SQL SERVER – Find All Servers From Local Network – Using sqlcmd – Detect Installed SQL Server on Network.

I have confronted numerous situations when these nerve-wracking errors crop up, and most of the time when I try to troubleshoot I notice that SQL Server services are neither running nor installed. If SQL Server is not installed as default instance SQL Server Browser should be running together with it; we will explore this further in Topic 5.

SQL SERVER - FIX : ERROR : (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: ) e40_7

2) Enable TCP/IP in SQL Server Configuration

When two or more SQL Servers are connected across network they do all communication using TCP/IP. The default port of SQL Server installation is 1433. This port can be changed through SQL Server Configuration Manager. TCP/IP should be enabled for SQL Server to be connected.

Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> Select TCP/IP

SQL SERVER - FIX : ERROR : (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: ) e40_1

Right Click on TCP/IP >> Click on Enable

SQL SERVER - FIX : ERROR : (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: ) e40_2

You must restart SQL Server Services for all the changes to take effect. Right click and go to menu properties to select location where default port of SQL Server can be changed.

3) Open Port in Windows Firewall

Windows Firewall is very efficacious in protecting the Operating system from all sorts of malicious attacks. By default, many of the ports and services are refrained from running by firewall. Time and again, SQL Server ports are not open in firewall as well. All the ports on which SQL Server is running should be added to exception and firewall should filter all the traffic from those ports. As described, by default SQL Server runs on port 1433, but if default port is changed then the new port should be added to exception. If SQL Server has named instance (another instance besides default instance) is installed, SQL Server browser should also be added to the exception, as described in Step 7.

Go to Control Panel >> Windows Firewall >> Change Settings >> Exceptions  >> Add Port

SQL SERVER - FIX : ERROR : (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: ) e40_3

SQL SERVER - FIX : ERROR : (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: ) e40_4

Make the following entries in popup “Add a Port” and click OK.
Name : SQL
Port Number: 1433
Protocol: Select TCP

SQL SERVER - FIX : ERROR : (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: ) e40_5

SQL SERVER - FIX : ERROR : (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: ) e40_6

4) Enable Remote Connection

Enabling remote connection is another important, yet oft-neglected step that is frequently missed by database administrators while setting up SQL Server. If this feature is turned off SQL Server will function smoothly on local machine, but it will let another server connect to it remotely. By default this feature is ON in SQL Server 2008.

Right click on the server node and select Properties.

SQL SERVER - FIX : ERROR : (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: ) e40_9

Go to Left Tab of Connections and check “Allow remote connections to this server”

SQL SERVER - FIX : ERROR : (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: ) e40_10

5) Enable SQL Server Browser Service

If SQL Server is not installed as default instance but instead installed as named instance and also if there is no specific TCP/IP port configured, it will give rise to the error that is being discussed in this article. If SQL Server Browser service is enabled, it will allow the server to be connected through dynamic TCP/IP port. Enabling this service is a one-time process, as on enabling it once it will apply to all the instances installed on the same server.

Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> SQL Server Browser

SQL SERVER - FIX : ERROR : (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: ) e40_8

Right Click on SQL Server Browser >> Click on Enable

6) Create exception of sqlbrowser.exe in Firewall

As elucidated in Step 6, sqlbrowser service needs to be enabled for named instance. Windows Firewall may prevent sqlbrowser.exe to execute. So, it is imperative to add exception for the same in windows firewall.

Search for sqlbrowser.exe on your local drive where SQL Server is installed. Copy the path of the sqlbrowser.exe like C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe and create the exception of the file in Firewall, as delineated in Step 3.

7) Recreate Alias

It is getting quite common to create alias of SQL Server and use it in application. This will ensure that in future if any physical SQL Server has to be moved, it will not be required to change any code or connection string. You can simply create alias with the same name pointing to different SQL Server and it will start working instantaneously. I have observed that a couple of times due to internal error while recreating alias this error was fixed.

Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Native Client 10.0 Configuration >> Aliases

Delete the alias that is giving problem and recreate it with identical parameters.

SQL SERVER - FIX : ERROR : (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: ) e40_11

I have tried my best to include all the methods of fixing this error and if I have missed any, please leave a comment and I will be very glad to include them here. I have put in my effort to encompass this issue in one article that needs to be refereed when any connection error comes up.

Watch SQL in Sixty Seconds video to Resolve Connection Error:

[youtube=http://www.youtube.com/watch?v=1k00z82u4OI]

Reference : Pinal Dave (https://blog.sqlauthority.com)

SQL Error Messages, SQL Scripts, SQL Server Management Studio
Previous Post
SQL Server – Download PDF SQL Server Cheat Sheet
Next Post
SQLAuthority News – SQL Server Energy Event with Rushabh Mehta – May 20, 2009

Related Posts

658 Comments. Leave new

  • Mr Robert, what server did you reboot? is that answer for me???

    Reply
  • THANKS..THANKS ALOT………

    Reply
  • I have come across that problem and i spend all day to find obivious thing

    all protocols enables. firewall disabled , can connect locally but not from other machines
    system Windows 2008 + sql express 2008 r2 (all 64Bit)

    solution:
    Make sure that not only TCP/IP is enabled but as well on IP Addresses Tab You must enable specific IP you are using to connect. (somehow by default they were off on x64 system)

    Regards

    Reply
  • Thank you for your topic, but I couldn’t follow the solution you showed because I couldn’t modify anything in the firewall. The reason is McAfee Anti virus.
    When I open Windows Firewall I immediatly face a yellow line with the following content: “These settings are being managed by vendor application McAfee Personal Firewall”
    In other words, the firewall is not able to be modified because of McAfee.

    Please can you give me an idea to solve that problem.
    Because I am currently not able to change my Anti virus.

    Thanks

    Reply
    • Hi YAZAN,
      You could have visited the site of mcafee instead of posting the problem to this blog. Follow these steps and it will solve the problem…
      1. Open MCAFee Security Center
      2. Click on personal firewall plus.
      3. Goto Options
      4. Goto System Services.
      5. Search for the Microsoft SQL Server Port 1433 from the list box and check it if you find it, else just add the TCP IP port.
      And you are done…

      Reply
  • I cannot connect to a machine with sql 2000 server from a machine with SQL 2005 server instance i get the error “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) (.Net SqlClient Data Provider)”

    Reply
    • Dear Paul,
      Follow the steps for your problem.
      1. Enable the TCP/IP protocol using the Surface Area Configuration Utility
      2. Make sure the TCP/IP protocol is enabled in the SQL Server Configuration Utility
      3. Make sure the SQL Server browser is started. Note this step is optional. It is possible to set the SQL Server instance to use a fixed IP address – but this is non-standard for named instances
      4. Make sure SQL Server and SQL Server Browser are exempted by the firewall on the server machine. This is done by putting sqlservr.exe and sqlbrowser.exe as an exception in the windows firewall.
      (Note: In order to get things to work. You might need to completely reboot the server machine after making the changes. Just by restarting all the services might not solve the problem.)

      Thanks.

      Reply
  • Thanks so much for this post. I was having the same issue when conneting to a named sql server instance, and not the default one.

    Reply
  • I got this error when i try to link mssql to mysql…but can’t find any help online..hope u can help me..

    my error:

    Named Pipes Provider: Could not open a connection to SQL Server [3].

    thanks…

    Reply
  • Hi All,

    I have tried all above mentioned solutions to fix the error. But still I am getting same error.

    I am using Sql Server 2008 Enterprise Edition(32 Bit).

    Please , let me know what is the problem.

    Reply
  • Hi Malaya Sinha,

    I have done the above as you advice but still cannot connect to an sql 2000 server.

    please help

    Reply
  • hi malaya,

    i have tried the above instructions but still get the same error.

    Reply
  • I can connect and view 2008 sqlexpress db from Management studio; I can also connect once from Visual Studio 2005, while developing project; but after one connection, I cannot re-connect and instead get this error. The db is local so not a remote connection issue.

    Reply
  • Wow, thanks a lot … Again! You are still my hero!

    Reply
  • Many thanks, it helped me.

    Reply
  • Jason Vollaire
    October 7, 2010 3:09 pm

    Hi Dave

    I am quite new at SQL Server database administration & T-SQL report building (BI). I have often referrred to your write ups on various points and have found your advice and posts extremely helpful.

    Thank you for sharing your knowledge with the community, it has been a big help!

    Best Regards

    Reply
  • Hi Pinal Dave,

    I tried all your suggestions still does not work. I posted my question in the link below

    Let me know if you have any suggestion.

    Sompop

    Reply
  • I followed your steps and it helped, but I am using newer OS (Windows 7) so the firewall configuration is different. If I turn off firewall, connection works. If I re-enable firewall, connection breaks. I have rules for SQL and SQL Brower. What else do I need?

    Thanks for your post.

    Reply
  • I have same error message but the scenario is different.I have a xp machine with sql server 2000.When i connect that db from my client xp machine sql server 2005 it connects but when i try to connect from windows server 2008 with sql server 2005 it give me error message as shown above in article.

    Reply
  • Great article. Thanks!

    Reply
  • Hello ,

    ” OLE DB provider “SQLNCLI” for linked server “xx.xxx.xxx.xxx” returned message “The partner transaction manager has disabled its support for remote/network transactions.”.
    Msg 7391, Level 16, State 2, Procedure reminder, Line 5
    The operation could not be performed because OLE DB provider “SQLNCLI” for linked server “xx.xxx.xxx.xxx” was unable to begin a distributed transaction. ”

    When i was connect local sql server to online sql server .

    Thanks. for advanced.

    Reply
  • This solved my problem. Thanks a lot!

    Reply

Leave a Reply