IIS: Connecting to .mdf database - web config problem
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 Sourc开发者_JAVA百科e=.\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,
IlijaFollow these steps: 1: Attach your Northwind.mdf to your Sql Server 2005 on your server using the Sql server Management studio. 2: Modify the connectionstring in your web.config so that it points to the db on your server.
How to detach / attach db.
A couple things to check:
- Is the database file really at that location?
- Does the app pool have read/write rights to that directory?
- Are the SQL Express services actually running?
Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\ASP\TestSite\\App_Data\\Northwind.mdf;Integrated Security=True;User Instance=True
And then read How to configure SQL Server 2005 to allow remote connections
And be sure the location of Northwind.mdf is right!
Here's couple of points to check:
If you're deploying into a shared hosting environment the chances are that the host won't be running SQL Server on the web servers. Ask them to confirm and provide you with the .
The connection string you're using looks suspicious. If SQL server has been installed on your server but as the "Default" instance then you don't need the
\SQLEXPRESS
part of the connection stringData Source
. Just use.
or(local)
.If it is indeed SQL Express installed and it's been installed with the instance name
SQLEXPRESS
then check that the site identity has a valid login and the correct permissions on your database. This identity could be the worker process account (NETWORK SERVICE
,ApplicationPoolIdentity
, custom account) or the site's IIS anonymous account (if ASP.NET impersonation is enabled).
My final point is important:
- The
AttachDbFilename
andUser Instance=True
are specific to SQL Express which supports a concept known as "User Instances". This feature is not suitable for dedicated or shared hosting environments.
My advice is to
- find out exactly what version AND edition of SQL Server is available for you to use
- find out where its hosted (locally on your server, or on another machine)
- find out if it's configured as the "Default" instance or a named instance
精彩评论