Add user to SQL Server 2008 - permission denied

Tomas Aschan picture Tomas Aschan · Feb 11, 2009 · Viewed 10.5k times · Source

I have recently had some problems that I think might be helped by debugging my ASP.NET MVC application in IIS instead of with the default ASP.NET Development Server. However, when I try this the application can't access the database server (MS SQL Server 2008 Express) - it works fine on the Development Server though.

The error I get is

Cannot open database 'myDbName' requested by the login. The login failed. Login failed for user 'NT INSTANCE/NETWORK SERVICE'.

I assume it worked before because the development server accessed the database through my user account, and not via the network service like IIS.

I tried adding the user NETWORK SERVICE to the database, but it turns out I don't have the user privileges to do so - it doesn't matter that my Windows account that I log on to the server with is admin, or that I run the program in an administrator context. I just can't add another user to the DB.

How do I solve this problem?

Answer

teedyay picture teedyay · Feb 11, 2009

You could change the user that IIS runs under: it's a setting in the properties for the ApplicationPool that your web site's running under.

We do this all the time as it gives us better control over user access - that NT INSTANCE/NETWORK SERVICE account's a bit too magic for my liking...