Recently I faced an issue while database connectivity(SQL Server 2008 R2) on my Windows 7 machine for a web app.
Cannot open database "Database Name" requested by the login. The login failed.
Login failed for user ‘IIS APPPOOL\DefaultAppPool’.
This issue was related to security.
I could resolve the issue by creating a login for user IIS APPPOOL\DefaultAppPool and giving same user permission to respective database.
First of all Login needs to be created for the user “IIS APPPOOL\DefaultAppPool” in SQL Server.
Expand Security –> Right Click on Logins –> Click New Login…
Enter login name as “IIS APPPOOL\DefaultAppPool” and Click OK.
To give the permission to the database
Right Click on the Database –> Properties
Select Permissions –> Click on Search
Click Browse then Select “IIS APPPOOL\DefaultAppPool” user –> click OK –> click OK –> click OK