Solved

Named Pipes Provider, error: 40 - Could not open a connection to SQL Server

Posted on 2014-01-22
6
3,013 Views
Last Modified: 2014-01-24
Been dealing with this problem all day and nothing works.
We are using SQL 2008 on a Windows 2003 server.
Everything had been working fine until a few days ago when we renewed the certificate on the web server (I don't think this has anything to do with it).
I get the error when trying to use my web application:

Server Error in '/SMA13' Application.

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)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5063578
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity) +341
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +129
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +239
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
   System.Data.SqlClient.SqlConnection.Open() +125
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +123
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +319
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
   Login.Page_Load(Object sender, EventArgs e) +105
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1016


I thought it might be the connection between my web server and SQL server but I could ping them fine.
I even tried the telnet 1433 method and that connected fine.
TCP/IP and Named Pipes are enabled.
I even tried turning Named Pipes off, that didn't work.
I tried putting in the IP address itself in the connection string and that did not work.
EVERYTHING works perfect in development but when we try it on the webserver we get the error.
0
Comment
Question by:rr4406pak
6 Comments
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
Something to try ... use the fully qualified server name in your connection string, e.g.  servername.domain.net  instead of just servername.
0
 

Author Comment

by:rr4406pak
Comment Utility
Yep, we tried that. Still same error. This is the hardest problem I've ever come across in dealing with SQL.
0
 
LVL 16

Expert Comment

by:Surendra Nath
Comment Utility
it may not be a issue with SQL Server...
It may be an issue with the IIS

Can you try to write a desktop application (small one) to test if the SQL is working fine from the web server

if it is, then the changes that you did on the webserver is what affecting your SQL connection roll back the changes and see if that solves the issue.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:rr4406pak
Comment Utility
Maybe we should bring the web server and the SQL server down and restart them for the heck of it?
Would there be any particular order to bring the servers back up? SQL server first?
We're running out of ideas...
0
 
LVL 38

Accepted Solution

by:
Jim P. earned 500 total points
Comment Utility
Would there be any particular order to bring the servers back up? SQL server first?

I would do the SQL Server first. Then the web server.  

Another question, did any of the DC's change? Or reboot?

Named Pipes works by going to one DC and then the DC sends a token to the SQL Server to say "Yes you can give data to the Server/App/User." If tha DC is rebooted or loses connections the token becomes invalid.

With TCP/IP the web server gives it's SID to the SQL Server and then SQL goes to find a DC and says "Does this Server/App/User exist and not lying to me?" Whichever DC says "Yes" or "No" then SQL sends the data. If the session is broken for whatever reason the SQL can re-request the SID/credentials and then re-validate from any available DC.

I discourage NP and turn it off during setup of a SQL Server installation out of habit.
0
 

Author Comment

by:rr4406pak
Comment Utility
Solved the problem.
It turns out it was related to updating the SSL certificate on the web server.
It seems that once you install a new certificate something has to "sync" between the web server and its database server(s).
Once I brought both web and database servers down, then brought the database servers up first, then the web server last, it all started working again.
So be careful when updating your server certificates!
Thanks!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now