SQL SERVER – FIX : ERROR : Cannot open database requested by the login. The login failed. Login failed for user ‘NT AUTHORITY\NETWORK SERVICE’.

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

SQL SERVER - FIX : ERROR : Cannot open database requested by the login. The login failed. Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. errnt

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.

SQL SERVER - FIX : ERROR : Cannot open database requested by the login. The login failed. Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. errnt1

In almost all such cases, this should fix your problem.

Reference : Pinal Dave (https://blog.sqlauthority.com)

SQL Error Messages, , SQL Scripts, SQL Server Security
Previous Post
SQLAuthority News – Two Virtual Tech Days Sessions – Watch it Online
Next Post
SQL SERVER – Get Query Plan Along with Query Text and Execution Count

Related Posts

225 Comments. Leave new

  • Hi, that helped a lot. So simple and efficient way.
    Thank you.

    Reply
  • 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

    Reply
  • 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!

    Reply
  • Ivan Christiono
    December 17, 2013 3:15 pm

    thank you so much 2x, it was very helping me!

    Reply
  • Awesome!!!

    Reply
  • Just followed your instructions, very helpful, thankyou.

    Reply
  • Yazar Arafath
    March 8, 2014 11:44 am

    Awesome its working thanks to all

    Reply
  • THANK YOU!!!!! I am so glad I came across your post!

    Reply
  • Thanks.. For wonderful post.

    Reply
  • thank you so much sir your solution is work for me , you solved my problem. thank u so much

    Reply
  • Awesome solution, thanks a load :)

    Reply
  • tank you very much . my problem solved (:

    Reply
  • Muhammad Rafi
    July 8, 2014 12:22 pm

    not working for me. Please tell me why?

    Reply
  • Thanks, saved my day

    Reply
  • Cannot open database “mydb” requested by the login. The login failed.
    Login failed for user ‘GARIMA-VAIOGARIMA’

    Reply
  • Liviu Dumitrascu
    September 9, 2014 5:52 pm

    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.

    Reply
  • 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.

    Reply
  • 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)

    Reply
  • Thank you so much sir

    Reply
  • I faced this problem & your solution has helped me to resolve it. very simple & clear. Thank you

    Reply

Leave a Reply