locked
sql server connection problems RRS feed

  • Question

  • User1051635487 posted

    I am getting the below 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"}.

    I already configured my sqllserver  surface area configuration to allow remote connections.

    I am getting the above error when trying to open a connection Have a look at the code also.

    web.config

    ---------------

    <appSettings>
        <add key="ConnectionString" value="server=krishna;integrated security=SSPI;Database=AdventureWorks"/>
      </appSettings>

     

    public SqlConnection connect()
        {
            string cons = (string)ConfigurationSettings.AppSettings["ConnectionString"];
            SqlConnection conn = new SqlConnection(cons);
            conn.Open();
            return conn;
        }

     

    Help me out.

    Thursday, December 25, 2008 8:27 PM

Answers

  • User-1171043462 posted

    The Error states that the Server or the SQL Server instance is not running

    Try changing your connection string as

    <add key="ConnectionString" value="server=.;integrated security=SSPI;Database=AdventureWorks"/>

    or

    <add key="ConnectionString" value="server=.\SQLEXPRESS;integrated security=SSPI;Database=AdventureWorks"/>

     

    Also try to debug and see the value in string cons

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 26, 2008 12:05 PM

All replies