SQL Server was not found or was not accessible.

Created:

2016-11-16 13:04:47 UTC

Modified:

2017-08-16 16:38:26 UTC

6

Was this article helpful?


Have more questions?

Submit a request

SQL Server was not found or was not accessible.

Applicable to:

  • Plesk 11.x for Windows
  • Plesk 12.0 for Windows
  • Plesk 12.5 for Windows

Symptoms

  1. Upon attempt to visit a website in browser the following error page is thrown:

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

    OR

    Server Error in '/' 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)

    OR

    Server Error in '/' Application.
    Object reference not set to an instance of an object.
    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.NullReferenceException: Object reference not set to an instance of an object.
  2. Website loads a long time. In Event Viewer following error occurs:

    Process information: 
    Process ID: 4636
    Process name: w3wp.exe
    Account name: NS1\\IWAM_plesk(default)
    Exception information:
    Exception type: SqlException
    Exception message: 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

Cause

The ' web.config ' file should contain entries to connect to database (database name, appropriate user, password). But incorrect credentials for the SQL server are specified in the site settings or database itself is not accessible.

Resolution

  1. Contact website developer to fix the issue.

  2. Check for the ' Data Source ' values in the 'web.config' file. It should point to the correct SQL Server instance name. For example:

    Incorrect:

    <add name="BC" connectionString="Data Source=localhost;Initial Catalog=example.com;User ID=UserName;Password=****;" providerName="System.Data.SqlClient" />

    Correct:

    <add name="BC" connectionString="Data Source=SRV\\SQLEXPRESS;Initial Catalog=example.com;User ID=UserName;Password=****;" providerName="System.Data.SqlClient" />
  3. To check all connection strings run the following command:

    C:\\> findstr ConnectionString C:\\inetpub\\vhosts\\example.com\\httpdocs\\subdomain\\web.config

    <add name="exampleConnectionString1" connectionString="Data Source=SRV\\SQLEXPRESS;Initial Catalog=example.com;User Id=User1;Password=******;Pooling=False" providerName="System.Data.SqlClient" />
    <add key="ConnectionString" value="Data Source=SRV\\SQLEXPRESS;Initial Catalog=example.com;User Id=User1;Password=******;Pooling=False" />
    <!--<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;user id=User2;password=******" cookieless="false" timeout="180" />-->

    Please note that 'SRV\\SQLEXPRESS' is a placeholder for the SQL server instance name. Real name could be found from the service properties:

    sc \\\\<server_hostname> query | findstr MSSQL
  4. In case the ODBC connection is set via Plesk, the data source should be corrected from Plesk, but not in the 'web.config' file directly.

  5. If remote SQL server is defined in web.config , make sure that it is accessible from the issued server (SQL Management Studio can be used for this purpose).

Have more questions? Submit a request
Please sign in to leave a comment.