views:

5806

answers:

3

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?

+1  A: 

NETWORK SERVICE is a special account. If your database server is on another machine from your IIS server, you need to add the account:

\$ as a user for the database. So if you're on a IIS Server called LISA on the SPRINGFIELD network, you would need to grant access to SPRINGFIELD\LISA$ to your database. Note the dollar sign which denotes your user as a machine account and not an actual person.

If your database server and your IIS server are one and the same, grant access to the account "NT AUTHORITY\NETWORK SERVICE". That's the whole name of the account. And that should work.

Dave Markle
That's the problem - I am not allowed to grant access to any user accounts. teedyay's suggestion (changing the default user in the Application Pool in IIS) did solve the problem. Are there any obvious drawbacks with that workaround that I should be aware of?
Tomas Lycken
No, as long as you manage the account properly, that's a good solution. Too bad you don't have DBA's that could set this up for you if you don't have the access!
Dave Markle
The thing is, this is my private laptop that I use for hobby development. I am the only one accessing the site, and it is only accessed locally - I just want this to be able to test the stuff in an environment in which it is really supposed to be able to run.
Tomas Lycken
+2  A: 

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...

teedyay
A: 

Are you running a non-english Operation System?

For some reasons, the account name of "NT Authority\Network Service" has been localized in other languages.
Sadly, a lot of programs have the account name hard coded to the english name, and won't find the Network Service when running on foreign versions of Windows.

Sam
I am in fact running on a Swedish version of Windows Vista, but I did take that into account. I translated the error message so you guys would be able to read it... ;)
Tomas Lycken
I'm not talking about the error message: someone at MS decided to translate the account login names - problem is, some software has the english account names hard coded, and won't work on localized versions of Windows. Remember, they didn't just translate the display names, they translated the login names as well, which are used by software to identify those accounts.
Sam