This error is quite common and I have received it few times while I was working on a recent consultation project.
Cannot open database requested by the login. The login failed.
Login failed for user ‘NT AUTHORITY\NETWORK SERVICE’.
This error occurs when you have configured your application with IIS, and IIS goes to SQL Server and tries to login with credentials that do not have proper permissions. This error can also occur when replication or mirroring is set up.
If you search online, there are many different solutions provided to solve this error, and many of these solutions work fine. However, I will be going over a solution that works always and is very simple.
Fix/Workaround/Solution:
Go to SQL Server >> Security >> Logins and right click on NT AUTHORITY\NETWORK SERVICE and select Properties

In newly opened screen of Login Properties, go to the “User Mapping” tab. Then, on the “User Mapping” tab, select the desired database – especially the database for which this error message is displayed. On the lower screen, check the role db_owner. Click OK.

In almost all such cases, this should fix your problem.
Reference : Pinal Dave (http://blog.sqlauthority.com)




Simple and nice explanation.
Is there any other way around this without having to give db_owner rights? Thanks.
Excellent explanation.
thanks..
Hi,
Good to see your blog. It contains a lot of useful info. However, my problem doesn’t get resolved with this article.
I have a sharepoint server (2007) configured and while setting up the configurations, i started to get this error:
Login failed for user ‘NT AUTHORITY\LOCAL SERVICE’. [CLIENT: xxx.xxx.xxx.xxx]
Description: Cannot open database “SharedServices1_DB_8b3d821a-aea9-425d-bac9-87b4b4c1ac70″ requested by the login. The login failed.
my Shared Service Provider is configured to run under the above account with permissions as you mentioned above in your article.
Hi,
The database is set as ’standby and read only’ mode because the database being set as log shipping (subscriber). I can’t change as per your recommendation. What should be done before that?
Thanks.
Thanks so much! that helped!
hi
when i enter the following command in the command prompt:
psconfig -cmd standaloneconfig
four steps pass without any problem. in the step 5 of 10, i get the following error:
Failed to register SharePoint services.
An exception of type System.Data.SqlClient.SqlException was thrown. Additional exception information: Cannot open database “SharedServices1_DB_af35e620-5472-42d9-af7a-b78a20caf33e” requested by the login. The login failed.
Login failed for user ‘TEST\Administrator’.
since the problem seems to be the same as what u mentioned here, i tried the solution. but, in the User Mapping section of the Login Properties of NT AUTHORITY\NETWORK SERVICE, i couldn’t find SharedServices1_DB_af35e620-5472-42d9-af7a-b78a20caf33e. there are totally 8 items in the list, four disabled:
master
model
msdb
tempdb
and four enabled:
SharedServicesContent_7e…c9
SharePoint_AdminContent_eb…91
SharePoint_Config_18…ac
WSS_Content
the disabled ones’ db_owner is unchecked and the enabled ones’ db_owner is checked. i mean the role list is disabled or enabled.
now, what can i do?
thx
besides, when opening the User Mapping page, Microsoft SQL Server Management Studio pops up an info dialog indicating:
One or more databases are inaccessible and will not be displayed in the list.
Hi Pinal,
I have restored a database and I get this error while i try to connect my application to the database. It fails for my application user name and not for NTAuthority.
Can you suggest what could be the problem.
Thanks
Namrata
Thanks! it solve my problem within second that i had debugging the error few days!
Excellent thank you..
Thanks man.. you are the best..
The tip worked like charm..