You are trying to jumpstart an existing ASP.NET site on a new IIS 7.5 server under Windows 7 or under Windows 2008 R2, and you are getting this error message:
Cannot open database “YourDB” requested by the login. The login failed.
Login failed for user ‘IIS APPPOOL\DefaultAppPool’.
The problem is in IIS 7.5 DefaultAppPool settings.
Windows 2008 Server with IIS 7 runs DefaultAppPool using NetworkService user:
Windows 7 and Windows 2008 Server R2 with IIS 7.5 run the same pool under a different user – ApplicationPoolIdentity:
On the picture above from IIS 7.5 you see a correct setting for DefaultAppPool row.
All you need to do is to change that setting on your machine. Use IIS Admin – Application Pools. Right mouse click on DefaultAppPool row select Advanced Settings. A first setting under Process Model group is Identity. Select it and using a drop down list change Built-in account from ApplicationPoolIdentity to NetworkService.
Click Recycle button in the Action bar (not shown).
Next time I run across this error, I do not want to spend an extra minute on it.
[And the next time just falls on 2011-03-03 at 23:43 - Thank you 'Thigh-master'.]
I just tested these recommendations on latest Windows 2008 R2 Server with IIS 7.5, and it works.
2015-01-10 SA
I just tested this on Windows Server 2012 with SQL Server 2012 Express and it works there as well!
Allowing IIS APPPOOL\DefaultAppPool account is not the best practice but for development sake only.
If you have a development account in your environment that has full access to your database and dev environment, then use it as your custom identity account in your app pool.
In actual production environment you will be using a service account that has proper access to the database and IIS as your custom identity account in your app pool