Labels

slider

Recent

Navigation

Could not open a connection to SQL Server

could not open a connection to SQL Server, error: 40, a network-related or instance-specific error, Named Pipes Provider

Introduction

One day, I was attempting to connect with MS SQL Server but it didn't succeeded not even after making attempt once more and once more. I ran into error provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server on server. I'm providing you all necessary steps to resolve issue error: 40 - Could not open a connection to SQL Server. To succeed this issue, I would recommend to experience gave all strides one by one until your issue get resolve. This error comes out in many ways so that you need to check out all steps provided in this article until you succeed your issue.  

Detail Error Description:

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)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: 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)
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1016



Step 1:    First Step check your SQL services are running fine.

Step 2:    Click on “Start Window” and expand “Microsoft SQL Server 2008 R2” and click on “SQL Server Configuration Manager”.

SQL-Server-Configuration-Manager

Step 3:   Now click on left pane “SQL Server Services” and check for “SQL Server (SQLEXPRESS)” running or not, if it is experiencing in green colour then it’s working fine.


SQL Server (SQLEXPRESS)



Step 4:  Now check for “SQL Server (MSSQLSERVER)”, if it's experienceing  be in green color means running fine.

SQL Server (MSSQLSERVER)

Step 5: Now check for “SQL Server Browser” running or not, you've to make sure it's green marked.


SQL Server Browser


Step 6: Now click on “Aliases“ left pane, make assure on right pane that  there should be empty aliases, if requires then should recreate from fresh.

Aliases

Step 7: Now check for SQL Server Default Portal 1433, if you have not already added then follow to open “Ctrl + R”, type “Firewall.cpl” then Firewall will open and Click on “Advanced Settings”.

Advanced Settings


Step 8:
Click on “Inbound Rules” in left pane and click on right pane “New Rule”.

New Rule


Step 9: Then Click on “Protocol and Ports” and click on “Specific local ports” and write SQL default Port No “1433”.

Protocol Ports


Step 10: Now write name on SQL Port Name and click on “Finish” button.

 Add Port Name

Step 11: Now click on “Client Protocols” in left pane, next click on right pane “TCP/IP” and click on “Property” then you check that your default Port “1433” has been populated.

SQL Port 1433



Step 12: Now Open “SQL Server Management Studio” and right click, now property window open and click on “Property”.


SQL Server Management Studio

Step 13: Now click on “Connections” option and Check option “Allow remote connections to this server” and click now on “OK”.


Allow remote connections to this server

Step 14: You have to Ping for your IP Host Address on your command prompt  "cmd" console.

Ping IP Host

Step 15: Check for Firewall blocking SQL Server Port 1433

Step 16: If you have already access to development machine, production server then it'll be helpful greatly. Press (Windows + R) to open Run window to launch program quickly.  Now type “EVENTVWR” and a new window'll be open, now expand left pane, you'll be able to check here “Windows Log” to look into issue very closely and specifically.

Step 17: We can use also Netstat Command to display  how communicating with other computers or networks.

netstat [-a] [-b] [-e] [-f] [-n] [-o] [-p protocol] [-r] [-s] [-t] [-x] [-y] [time_interval] [/?]


Netstat Command


Authentication And Host Name Setting (SQL Server Error 25 And 27)

I am getting few queries routinely regarding authentication and host name resulting issue into SQL error No 25 & 27 to resolve these issues attempt below points and I posted this error SQL Server Error 25 And 87 with more detail in my earlier article.
  • Verify your Authentication whether it's Windows or SQL Server
  • If using local SQL database then you'll able to use . (dot) only instead of server name. 
  • Enter your correct host name (hostname\SQLEXPRESS), myhostname\SQLEXPRESS (in case of SQL Server Express) or (myhostname\mssqlserver). 
  • You'll also attempt alternatively (localhost\SQLEXPRESS) or (localhost\mssqlserver).

Conclusion

I have attempted my best to incorporate all fixing to dispose of this quite common issue of error: 40 – Could not open a connection to SQL. You'll keep posting me up message, if you still continue to face any further issue.

Suggested Links:

Video:Could not open a connection to SQL Server


Share

Anjan kant

Outstanding journey in Microsoft Technologies (ASP.Net, C#, SQL Programming, WPF, Silverlight, WCF etc.), client side technologies AngularJS, KnockoutJS, Javascript, Ajax Calls, Json and Hybrid apps etc. I love to devote free time in writing, blogging, social networking and adventurous life

Post A Comment:

63 comments:

  1. Thank you so much for posting this article Anjan. Helps me lot.

    ReplyDelete
  2. Hello Sir................,
    Above Problem occure in my pc also
    (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: SQ L Network Interfaces, error: 26 - Error Locating Server/Instance Specified),,,,,,,,,,,,,,,,,,
    But In My PC I have use "MICROSOFT SQ L SERVER 2012 "...........then can u tell m this is all steps are common or different

    ReplyDelete
    Replies
    1. Priya, It sounds like are you missing/incorrect your data source name, you can check link http://msdn.microsoft.com/en-us/library/ms191464.aspx , it will work perfectly for SQL Server 2012, pls check all steps mentioned above correctly.

      Delete
  3. On 'sql server services' SQL Server (MSSQLSERVER)” is missing. I tryed ti uninstall-reinstall SQL SERVER but the problem still continous.
    Any suggestions ?

    ReplyDelete
    Replies
    1. Can you please share your exact problem right now facing, did you check all steps mentioned above.

      Delete
    2. 11 steps are ok , 12 step how to possible without open sql server

      Delete
    3. You can ask for your SQL database provide to confirm “Allow remote connections to this server” if database is on remote machine.

      Delete
  4. SQL Server (MSSQLSERVER) is missing...

    Please suggest me what i do next

    ReplyDelete
  5. check for Start the service for (MSSQLSERVER), press Ctrl+R then locate SQL Server (MSSQLSERVER) service, then mouse right click, go "Properties", click tab "Log On" try with "This account". check for all SQL server services to green.

    ReplyDelete
  6. Thanks to you bro. Keep Posting for another tutorials. It works at me.

    ReplyDelete
    Replies
    1. Sure tbabbit, I'll keep posting for another good tutorials on ASP.Net (C#), SQL Server issues. Thanks for motivation.

      Delete
  7. hello sir, i hve same problem & i have tried ur suggested steps but it is giving same error. please suggest me what to do?

    ReplyDelete
    Replies
    1. I'm back from New Year, did you tried all steps. I thinks you should get your resolutions right in the mentioned steps.

      Delete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. Hello Anjan

    i followed all the steps but two steps i do not know how can i do it

    the first step is Sql server browses is shown in red not in green so how can i fix it

    the last step when i write in console prompt
    ping technologycrowds.com
    i got this :

    Pinging technologycrowds.com [216.239.34.21] with 32 bytes of data :

    request timeout
    request timeout
    request timeout
    request timeout

    Ping statistics for 216.239.34.21 :
    Packets : Sent=4, Received=0, Lost=4 <100% loss>

    ReplyDelete
    Replies
    1. Check Step #2, #3, #4, #5 carefully, you have to ping your website not www.technologycrowds.com so it also carefully, when you ping your website it will reply if sending request timeout then there is issue in your website.

      Delete
  10. @Anjan Kant
    I got this error to
    But when i tried above steps
    i didn get sqlserver (mssqlserver) services wht to do?

    ReplyDelete
  11. Please follow carefully Step 1, Step 2, Step 3, Step 4, Step 5, Step 6 to resolve your issues after that you still find the same issue (sqlserver (mssqlserver) services) let me know.

    ReplyDelete
  12. Thank you sir it working properly This artical help to me and other also ....Thank you so much...

    ReplyDelete
  13. Thanks.Now i am able to connect to remote database and it is working completely fine

    ReplyDelete
  14. TITLE: Connect to Server
    ------------------------------
    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: SQL Network Interfaces, error: 28 - Server doesn't support requested protocol) (Microsoft SQL Server, Error: -1)

    ReplyDelete
    Replies
    1. " Verify that the instance name is correct and that SQL Server is configured to allow remote connections" did you checked this one and again verify all steps given above, if you still persists the issue let me know.

      Delete
  15. I followed through yoga highlight your guidelines, and having problem with step 4 & 5.
    + On step 4, I do not have SQL Server( MSSQLServer ) on my SQL Server Configuration Manager.
    + On step 5, I right click to start SQL Server Browser, and it failed. This is the message that I got
    " the request failed or the service did not respond in a timely fashion. Consult the event or other applicable error logs for details"
    Please please help me with this issues.
    Thank you

    ReplyDelete
    Replies
    1. Providing you few links to resolve Step 5 issue 1) http://blog.sqlauthority.com/2011/03/29/sql-server-fix-error-the-request-failed-or-the-service-did-not-respond-in-timely-fashion-consult-the-event-log-or-other-applicable-error-logs-for-details/ 2) http://stackoverflow.com/questions/1617402/the-request-failed-or-the-service-did-not-respond-in-a-timely-fashion 3) https://biatlink.wordpress.com/2013/04/29/sql-server-request-failed-or-the-service-did-not-respond-in-a-timely-fashion/ if you still facing the issue then let me know.

      Delete
  16. provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

    ReplyDelete
    Replies
    1. Go to Sql server configuration manager in sql native client configuration, enable client protocols

      Delete
  17. Already provided steps 16 to resolve the issue "provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)" if you are still missing then can check this link also http://blogs.msdn.com/b/sql_protocols/archive/2007/03/31/named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server.aspx

    ReplyDelete
  18. Hi, Thank you so much for this great width thank the hope that it will be successful

    ReplyDelete
  19. how can i perform the task of connecting a database(mdf) file in remote machine and accessing it my machine using windows form(C#).i am not able to establish a centralized database in my laptop.plz help

    ReplyDelete
    Replies
    1. You can access remote database in two ways as following:
      1) You can develop webs service and host it online to access across the network.
      2) You can assign a public IP address and access it remotely.

      Delete
  20. thanks for this solution !!!!!!!!

    ReplyDelete
  21. Hi Anjan,

    I couldn't connect to the SQL SERVER 2005 database engine to itself, but It can be connected to the other PC's in the LAN. Please do the needful.


    Narendran N
    n4narendran.theblogspot.in

    ReplyDelete
    Replies
    1. Can you check your firewall (PC Security) which is stopping to connect your own PC, can you specify your error message while not connecting.

      Delete
  22. Hi Anjan kant, Thanks for detailed explanation. But facing a error like that only.
    Follow the all steps as mentioned.
    Please through some light on this issue. Its very urgent.

    Thanks in advance,
    Bhaskar N

    ReplyDelete
    Replies
    1. Bhaskar, Can you specify your error exactly here, so that I can tell you exactly.

      Delete
  23. TITLE: Connect to Server
    ------------------------------

    Cannot connect to ASWAK\SQLEXPRESS.

    ------------------------------
    ADDITIONAL INFORMATION:

    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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (Microsoft SQL Server, Error: -1)

    ReplyDelete
    Replies
    1. Did you check all 17 steps, if you confirm all steps, it is very sure, your SQL server will connect. If any more required let me know.

      Delete
  24. TITLE: Connect to Server
    ------------------------------

    Cannot connect to NG.

    ------------------------------
    ADDITIONAL INFORMATION:

    Login failed for user 'ng\negar komputer'. (Microsoft SQL Server, Error: 18456)

    For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=18456&LinkId=20476

    ------------------------------
    BUTTONS:

    OK
    ------------------------------
    this is my error

    ReplyDelete
    Replies
    1. Microsoft SQL Server, Error: 18456 this error due to invalid User Name/Password, please confirm your SQL Server for valid login detail.

      Delete
  25. how can i download microsoft sql server 2008,please send me the link.32 bit os

    ReplyDelete
    Replies
    1. Here is a link http://download.cnet.com/Microsoft-SQL-Server-2008-Express-32-bit/3000-10254_4-75451532.html to download SQL Server 2008 (32 bit OS).

      Delete
  26. Replies
    1. Welcome, keep more reading on SQL Server error.

      Delete
  27. Hi Anjan Kant, Thanks for the Post Its resolved my Problem !

    You have described the solution briefly in your post Great!

    ReplyDelete
  28. Sir,
    When I open "Microsoft SQL Server Management studio"
    I get only two folder which is "Running Packages" and "Stored Packages" What should I do to sort out this problem?

    ReplyDelete
    Replies
    1. Here is a video link which demonstrates how to open Microsoft SQL Server Management studio

      Delete

  29. Sir, Please solve this problem

    Cannot connect to \SQLEXPRESS.

    ------------------------------
    ADDITIONAL INFORMATION:

    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: SQL Network Interfaces, error: 25 - Connection string is not valid) (Microsoft SQL Server, Error: 87)

    For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=87&LinkId=20476

    ReplyDelete
    Replies
    1. Check below points
      1) Verify your Authentication whether Windows or SQL Server.
      2) if using local sql database then you can use . (dot) instead of server name, try other one also
      3) enter correct host name: (hostname\SQLEXPRESS) myhostname\SQLEXPRESS (in case of SQL Server Express) or (myhostname\mssqlserver)
      4) try this one also (localhost\SQLEXPRESS) or (localhost\mssqlserver)

      Delete
  30. hello sir to do step 12 i need to login but I am getting same message saying named pipes provider error:40.... i cross checked above steps before step 11 i did all right. can you please help me.

    ReplyDelete
    Replies
    1. can you confirm me are you using your local db or remotely, also comply steps after/on steps 12 definitely it will help you.

      Delete
  31. Hello Sir, there are no items in the main(right panel) when i click SQL server services as said in step 5. What might be the mistake.. Please help as soon as possible.

    ReplyDelete
    Replies
    1. First check that your SQL server services running or not through control panel or type immediate run window "services.msc" and check SQL Server services running or not.

      Delete
  32. Hello Sir, in Step 5,when i click on SQL server services no items are present to be shown. Please help me as soon as possible

    ReplyDelete
  33. error 40: so cannot find sqlexpress server so what I do...
    I not intall any sql server..
    I used only providing by visual basic2010 installing time given sqlexpress server...
    how to solve my error gime me in step wise...
    pls

    ReplyDelete
    Replies
    1. First of all, confirm your machine running SQL server running or not because this error is totally concerned with SQL Server, moreover check steps for 7 , 8, 9, 10, 15, 16, 17 carefully.

      Delete
  34. Hi,

    I have created a simple asp.net web application and I am trying to read data from the DB but I am getting the same error as the title of this article.

    My Server Name is localhost\SQLEXPRESS but I am using

    SqlConnection con = new SqlConnection("data source=.;database=master;integrated security=SSPI");

    this as my con object command.

    I have tried all the steps above, Can you please help and suggest as to why I am still getting this error.

    ReplyDelete
    Replies
    1. Are you able to connect SQL Server Management Studio directly as you provided login credentials here.

      Delete
  35. Hi Anjan

    I am facing the same issue on my live (not on my PC)site, my site works fine mostly, suddenly i starts showing me following error without any updations in any files:
    SqlException (0x80131904): 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: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]

    after some time it starts working automatically, what all i do is just wait for some time.

    could you please help me??
    Thanks in advance

    ReplyDelete
    Replies
    1. If are you using .mdf SQL server database file then you need to install SQL Server Express on that particular machine. So you can't use .mdf file without installation, if you are looking for embedded database then prefer SQLite, SQL Server CE (Compact Edition), RavenDB etc, these work without installation.

      Delete
  36. my mdf is missing from app data folder . and sm error ocuured what should i do pls help me

    ReplyDelete
    Replies
    1. if mdf file is missing then you should add mdf file in your app data folder.

      Delete