views:

417

answers:

3

Our website connects to a database correctly when running the website locally using the built-in web server. But, when we deploy the site to our server running IIS, we get a database connection error. The database server is different from our IIS server. Note that a trusted connection to a different database on the SAME server as IIS works fine.

What do we need to do to connect to a SQL database on a different server with a trusted connection?

A: 

I'd check the user account that app domain in IIS is using to connect to SQL Server. The account in IIS may not have access to network resources as well which would explain the trouble reaching the other database server.

Rick
A: 

Sounds like you need to configure the database server to provide access to the database you're trying to connect to.

Assuming SQL Server, log into SQL Server Enterprise Manager and under Security -> Logins, open the properties for the applicable user (probably the Network Service or ASP.NET account of the web server) and go to the Database Access tab and ensure that the Permit checkbox is ticked for the database you are connecting to.

J c
+2  A: 

When you're running a web site using Cassini, the account used by the web server process is your own account that you use to log on to your Windows machine. That account will be different on IIS.

Consider the security implications of opening the database up to a broader access than you may need with trusted connection. Perhaps you could use Windows authentication with a service account. That is, create an application-specific user in SQL Server with limited permissions. Then, you will get the benefits of connection pooling while avoiding passing credentials.

DOK
Does that mean running the application pool under a specific domain account (e.g. MYDOMAIN\myuser)? So all DB calls would go through MYDOMAIN\myuser?
Jim
Yes, I believe so. That does obfuscate the user's identity, but there are other ways to identify the user (database fields CreatedBy, ModifiedBy). One big benefit of one user is connection pooling. It also helps highlight which app is accessing the database, helpful when there are multiple such apps
DOK