SQL Server connection problem

Discussion in 'Databases' started by Crossbow, Jul 4, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. After an absence of about a week, I tried to run my ASPNET 2.0 app that connects to my SQLServer 2005 db on the sql2k502.discountasp.net server, and I get the error message '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, erro: 40 - Could not open a connection to SQL Server)'.I last ran my app about a week ago with no problems whatsoever. But, thinking that there might be some change in my pc, I ran the SQL Server Management Studio Express tool (which has always done a bang up job in the past). Same error. From 2 different pcs. Any ideas?
     
  2. Should be using TCP/IP not named pipes
     
  3. Bruce

    Bruce DiscountASP.NET Staff

    Add 'tcp:' in front of the SQL Server name in your connection string should force .net to connect via TCP/IP

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  4. I get the same problem too, but under different circumstances.

    I have an application where in a directory there's an administrator section. In visual studio, I created and administrator role and user. The user log's in using the asp.net 2.0 login control, then gets taken to the next page where there's a userinfo control. This works perfectly fine when I'm testing it out on my local computer.

    I upload the site, entirely as is (including the web.config file), to my discountasp.net host folder. When i run the application and try to log in, I get the error:

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

    Here's the top of the stack trace:
    [SqlException (0x80131904): 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +735043
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
    System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup) +820
    System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +628
    System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +170
    System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +130


    The other sections of my site, which do not require logging in, but pull information from the database, work fine with the same connection string. What is wrong here?

    Thanks!
    Dan
     
  5. Bruce

    Bruce DiscountASP.NET Staff

  6. Worked perfectly! Thanks for the help and pointer to the great article!
     
  7. Mr

    Mr

    Hi,

    I get the same error as Crossbow, I am using this connection string




    SqlConnection connString1 = new SqlConnection("Provider=sqloledb;Data Source=tcp:mssql03.discountasp.net,1433; Initial CataLog=DB_270453_gms; User Id=DB_270453_gms_user;Password=***");


    Please help me,


    Thanks
     
  8. Bruce

    Bruce DiscountASP.NET Staff

    Your connection string is wrong, change it to

    Provider=sqloledb;Data Source=tcp:mssql03.discountasp.net; Initial CataLog=DB_270453_gms; User Id=DB_270453_gms_user;Password=***

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  9. I'm getting the same error message but it occurs when attempting to retrievevalues inprofile objects. My connection to SQL Server 2000 is working and Iperformedthe steps in http://kb.discountasp.net/article.aspx?id=10413with the exception of those for Visual Web Developer since I'm using VS Pro.









    Line 73: public virtual string VideoType {


    Line 74: get {


    Line 75: return ((string)(this.GetPropertyValue("VideoType")));


    Line 76: }


    Line 77: set {



    Source File: c:\WINDOWS\microsoft.net\Framework\v2.0.50727\Temporary ASP.NET Files\root\b04f392e\93dbcc2f\App_Code.c-tbljjc.0.cs Line: 75

    Stack Trace:










    [SqlException (0x80131904): 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]


    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +735043





    Contents of web.config file:





    <configuration>


    <appSettings>


    <add key="Variable0" value="100" />


    </appSettings>


    <connectionStrings>


    <add name="DB_246244_resumeConnectionString" connectionString="Data Source=tcp:mssql01.discountasp.net;Initial Catalog=DB_246244_resume;User ID=DB_246244_resume_user;Password=*****"/>


    </connectionStrings>


    <system.web>


    <authentication mode="Forms"/>


    <anonymousIdentification enabled="true"/>


    <profile enabled="true">


    <properties>


    <add name="Var1" allowAnonymous="true"/>


    <add name="Var2" allowAnonymous="true"/>


    <add name="Var3" allowAnonymous="true"/>


    <add name="VarInt" allowAnonymous="true"/>


    <add name="VideoName" allowAnonymous="true"/>


    <add name="VideoType" allowAnonymous="true"/>


    <add name="VideoDesc" allowAnonymous="true"/>


    <add name="PictureType" allowAnonymous="true"/>


    </properties>


    </profile>


    <compilation debug="true"/>


    </system.web>


    </configuration>
     
  10. You are missing the following :

    <connectionStrings>
    <remove name='LocalSqlServer' />
    <add name='LocalSqlServer' connectionString='Data Source=<DB_Server>;Integrated Security=false;Initial Catalog=<DB_Name>;User ID=<DB_User>;Password=<DB_password>' providerName='System.Data.SqlClient' />
    </connectionStrings>

    which is used by the membership/role default provider.

    Vikram

    DiscountASP.NET
    www.DiscountASP.NET
     
  11. That was my problem. Thanks.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page