IIS: Connecting to .mdf database - web config problem

ilija veselica picture ilija veselica · Dec 21, 2010 · Viewed 10.1k times · Source

Locally I connect to Northwind.mdf but when I upload application to remote server then I get following error:

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)

These are few options I tried:

<connectionStrings>
        <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Northwind.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>

The above one work locally.

<connectionStrings>
            <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\ASP\TestSite\App_Data\Northwind.mdf; Integrated Security=True;Connect Timeout=30;User Instance=True;Trusted_Connection=Yes"/>
        </connectionStrings>

On server is installed SQL Server 2005

Thanks,
Ilija

Answer

NotMe picture NotMe · Dec 21, 2010

A couple things to check:

  1. Is the database file really at that location?
  2. Does the app pool have read/write rights to that directory?
  3. Are the SQL Express services actually running?