Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3326
  • Last Modified:

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

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
rr4406pak
Asked:
rr4406pak
1 Solution
 
knightEknightCommented:
Something to try ... use the fully qualified server name in your connection string, e.g.  servername.domain.net  instead of just servername.
0
 
rr4406pakAuthor Commented:
Yep, we tried that. Still same error. This is the hardest problem I've ever come across in dealing with SQL.
0
 
Surendra NathTechnology LeadCommented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
rr4406pakAuthor Commented:
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
 
Jim P.Commented:
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
 
rr4406pakAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now