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

    Question

  • after lots  of goes and back, I have the same problem but it is related to my Visual studio too. Because I can access to the same database  for new projects but when I use an existing project with a new default page I get the same error.
    I am using visual studio 2005 connecting to MSSQL 2008 in server that has an instance of SQLServer express 2005 too
    the code for boht new and existing project is bellow

    I appricate any help

     

    protected void Page_Load(object sender, EventArgs e)

    {

     

    SqlConnection cn = new SqlConnection();

     

    string s = "Data Source=FRONTEND\\RNMSSQL2008;Initial Catalog=LSA;Persist Security Info=True;User ID=sa;Password=mypassword;Connect Timeout=30";

    cn.ConnectionString = @s;

    cn.Open();

     

    SqlCommand mycmd = new SqlCommand();

    mycmd.CommandText =

    "Select * from ASG_lot";

    mycmd.Connection = cn;

     

    SqlDataReader myreader;

    myreader = mycmd.ExecuteReader();

     

    while (myreader.Read())

    {

    Response.Write(myreader[

    "Lot_Number"].ToString());

    }

    }

    Tuesday, March 16, 2010 2:18 PM

Answers

All replies

  • Tuesday, March 16, 2010 2:32 PM
  • 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:

    Line 19:             string s = "Data Source=FRONTEND\\RNMSSQL2008;Initial Catalog=LSADev;Persist Security Info=True;User ID=sa;Password=mypassword;Connect Timeout=30";
    Line 20:             cn.ConnectionString = @s;
    Line 21:             cn.Open();
    Line 22:             SqlCommand mycmd = new SqlCommand();
    Line 23:             mycmd.CommandText = "Select * from ASG_lot";

    Source File: c:\Inetpub\wwwroot\LSA_Pilot\Default.aspx.cs    Line: 21

    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) +4846887
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
       System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +4860189
       System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +90
       System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +342
       System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
       System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
       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) +31
       System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +433
       System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
       System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
       System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
       System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
       System.Data.SqlClient.SqlConnection.Open() +122
       _Default.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\LSA_Pilot\Default.aspx.cs:21
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Control.LoadRecursive() +50
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
    


    Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082
    Tuesday, March 16, 2010 3:16 PM
  • Hi,

    Here's a full documents on how to sovle that problem, please check each step mentioned in that document.

    http://msdn.microsoft.com/en-us/library/dd857537(VS.85).aspx

    Thanks.
    Microsoft Online Community Support Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, March 18, 2010 5:17 AM
  • Line 19:             string s = "Data Source=FRONTEND\\RNMSSQL2008;Initial Catalog=LSADev;Persist Security Info=True;User ID=sa;Password=mypassword;Connect Timeout=30";
    Line 20:             cn.ConnectionString = @s;

    You have a @ sign in front of s. Why this @? Do you know how will the connectionstring be translated at the end? "\\" must be translated to one \, otherwise the connection is broken since the whole string is considerred as servername which is invalid.
    Thursday, March 18, 2010 9:46 PM
  • Hi Thanks for your resonse but still it I am the same spot. "@" do not change sitution. without @ It works in new project but it doesn't work in existing project . Default form  is identical.

     

     

    Friday, March 19, 2010 2:44 PM
  • Hi Thanks for your resonse I checked all the step that the reason it works in new project.  it doesn't work in existing project . Default form  is identical.

     

    Friday, March 19, 2010 2:48 PM
  • The Only Thing I have to add it may help is this:

    As you might know VS2005 doesnot work with MSSQL2008 and you need to run "VS80sp1-KB954961-X86-INTL.exe" to get it work. I found this patch will not working with VS2005 standard Version and it need to run on VS2005 Professional .

    So I remove Standard and install profession Visual studio 2005.  Now I am thinking maybe existing project  still use the standard version DLL during runtime . Now my question is this how can get rid of that ?

     

     

     

    Friday, March 19, 2010 2:53 PM
  • I have no idea about the standard vs. professional (people in SQL Server Data Access forum are unlikely to... maybe try a Visual Studio forum), but to figure out why one project can connect but one can't:

    I'm assuming these are on the same client machine, so I guess there is probably a difference in connection string, but it is just hard to find. Can you run them both under the debugger and copy the Connection String out of the SqlConnection object for each, and then compare the two for differences?


    This post is provided 'as is' and confers no express or implied warranties or rights.
    Friday, March 19, 2010 4:42 PM
  •  

    The Connection String for Both is

    "Data Source=FRONTEND\\RNMSSQL2008;Initial Catalog=LSADev;Persist Security Info=True;User ID=sa;Password=rnsa;Connect Timeout=30"

    "Data Source=FRONTEND\\RNMSSQL2008;Initial Catalog=LSADev;Persist Security Info=True;User ID=sa;Password=rnsa;Connect Timeout=30"

    Which are identical. All the other property of Connection are the same. I checked them one by one.

    Thanks 

    Monday, March 22, 2010 4:12 PM
  • errorcode=-2146232060
    Wednesday, March 24, 2010 5:21 PM
  • Are you still getting this "Named Pipes ... 40" error message? Are you seeing exception at the same place? Thanks.
    Friday, March 26, 2010 9:56 PM
  • Unfortunatly, Yes I do. I am thinking it is because of refrenceing.

    I don't know how to fix it

    Monday, March 29, 2010 5:14 PM
  • Let's do this step by step

    Go to this blog post and check and make sure each item is addressed

    http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/


    This seems not so helpful to me, Thank you!
    Monday, September 27, 2010 11:15 PM