I use the following connection string when working on my dev machine:
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
This works every time.
However, when I go to deploy to a remote IIS server that is a dedicated host (SQLEXPRESS should work just fine without the worries associated with a shared server), the same connection string results in a failure to connect to the database.
The database files are stored in App_Data within the directory of the application on the development environment and on the deployment environment. I just can’t seem to connect to the database on the deployment environment (although the file is sitting there).
Do I need to have my host somehow give me a username / password so I can add it to the connection string? Or do I need to change my connection string in some other way?
I’ve never used SQLExpress (well not in anger) but remember that once you’re on IIS you’re running under a different account than when you’re debugging. This would be the account under which the IIS app pool is configured to run. So, when you say you want to use integrated security to access this database, you need to configure it to recognize that particular account (whichever it is, for example
NETWORK_SERVICE).In a hosting environment you’re probably better off just using SQL authentication, although that’s obviously less secure since you have to store the password somewhere. And you’d still have to change the DB security settings.
Otherwise, if you do know the account under which the app pool is running then it’s just a matter of configuring the DB to accept connections from it.