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 (https://blog.sqlauthority.com)
225 Comments. Leave new
Hi, that helped a lot. So simple and efficient way.
Thank you.
i tried updating user, and it worked. see below command
USE ComparisonData// databaseName
EXEC sp_change_users_login @Action=’update_one’, @UserNamePattern=’ftool’,@LoginName=’ftool’;
just replace user(‘ftool’) accordingly.
thanks
shashank
This did not work for me. My account was already set as DBO for my Northwind database. I really don’t know what else to do about this error. Thanks!
thank you so much 2x, it was very helping me!
Awesome!!!
Just followed your instructions, very helpful, thankyou.
Awesome its working thanks to all
THANK YOU!!!!! I am so glad I came across your post!
Thanks.. For wonderful post.
thank you so much sir your solution is work for me , you solved my problem. thank u so much
Awesome solution, thanks a load :)
tank you very much . my problem solved (:
not working for me. Please tell me why?
Thanks, saved my day
Cannot open database “mydb” requested by the login. The login failed.
Login failed for user ‘GARIMA-VAIOGARIMA’
Hi, I have an Server connected to Iseries machine via shadow. On Iseries I do not find any error codes. On Server I get the following error:
Date 9/8/2014 10:36:00 AM
Log Job History (Read queue SHADOW)
Step ID 1
Server SRV001
Job Name Read queue SHADOW
Step Name Read queue
Duration 00:00:09
Sql Severity 11
Sql Message ID 50000
Operator Emailed
Operator Net sent
Operator Paged
Retries Attempted 0
Message
Executed as user: NT SERVICE\SQLSERVERAGENT. A .NET Framework error occurred during execution of user-defined routine or aggregate “ReadMessageFromAS400Queue”: System.Runtime.InteropServices.COMException: CWB4016 – cwbCO_Connect returned error code 8411 System.Runtime.InteropServices.COMException: at MidasLib.Queue.ReadMessage() at MidasLib.Messages.spReadMessage(SqlString& sMessage, SqlString AS400, SqlString AS400Library, SqlString AS400Queue, SqlString AS400UserID, SqlString AS400Password) . [SQLSTATE 42000] (Error 50000). The step failed.
i spend my two days on that problem
Server Error in ‘/Mvc4_demo’ Application.
Cannot open database “MyDB” requested by the login. The login failed.
Login failed for user ‘IIS APPPOOL\ASP.NET V4.0 Integrated’
i was tried number of methods but it’s not solve please give me some guide line.
Hi All I am trying to install SCCM 2012 R2 but got below error I ma not sure what needs to done administrator account having system admin role.
2014-10-23 10:29:20.45 Logon Login failed for user ‘TEST\Administrator’. Reason: Failed to open the explicitly specified database ‘CM_SCCM’. [CLIENT: 192.168.1.5]
C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Log
c:\ ConfigMgrSetupWizard
10/23/2014 10:29:21 AM: ConfigMgrSetupWizard Error: 1 : Exception message: [Cannot open database “CM_SCCM” requested by the login. The login failed.
Login failed for user ‘TEST\Administrator’.], Exception details: [System.Data.SqlClient.SqlException: Cannot open database “CM_SCCM” requested by the login. The login failed.
Login failed for user ‘TEST\Administrator’.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
Thank you so much sir
I faced this problem & your solution has helped me to resolve it. very simple & clear. Thank you