Sunday, August 30, 2009

Login failed for user 'NT AUTHORITY\\NETWORK SERVICE'

I got this error when deploying my WCF + linq to SQL service to IIS. This happens because IIS runs under NT AUTHORITY\\NETWORK SERVICE. There are a couple of solutions here:

  • change IIS service to run under another user.
  • setup impersonation (complicated but ideal)
  • grant Network service access to the database ( quick but insecure)
Just to get it running on your test server you can use option three as explained below:
  • Just open up SSMS
  • log into database server
  • expand Security -> logins.
  • Right click logins and select new login
  • search login name
  • type in "network service"
  • in server roles check "public" and "sysadmin"
  • in user mapping select your database and give it "owner" and "public" rights
  • Click OK and your are all set