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

  • Alex Scianna
    May 17, 2012 3:23 am

    I don’t think this solution can possibly work for me. First off, NT AUTHORITYNETWORK SERVICE is not in my Security Login folder. But even if it were, the Database that I am timing out on no longer exists on the either the server on which I am creating the backup nor the server on which I am doing the restore. (I can see the database name out in an error log message on the server where the logon is timing out). The database which I am trying to restore is on both servers, is the database from which the backup ws created and is not the one being requested by the logon.

    So to sumarize MY problem, I am trying to restore a database from one server to another, but when I try put the backup file name in the Specify Backup dialogue box, I get a timeout on the server to which I am trying to apply the restore because the the Logon has requested a database that doesn’t exist anywhere. It did exist a long time ago but it did not exist yesterday when the backup was created.

    Apparently the database name is lingering somewhere but I haven’t been able to find it. Might you have any insight as to why the name of this non-existent database plays a roll in the backup/restore and how I can get rid of it?

    Thanks,
    Alex Scianna
    Monteat College

    Reply
  • Alex Scianna
    May 17, 2012 3:31 am

    PS:

    I realized when I got the confirmation to my post that NT AUTHORITYNETWORK SERVICE is just a user name, and I should substitute the login name that is failing. The point I failed to make is that the database name that the logon is requesting no longer exists and does not appear in the list of databases under the User Mapping tab for any user name.

    Thanks,
    Alex Scianna

    Reply
  • so tanks good post

    Reply
  • Sushanth Sreedharan
    May 29, 2012 12:40 pm

    Thanks , For this wonderful post. It really solved my problem. You have solved many of my queries earlier also.

    Best Regards

    Sushanth Sreedharan

    Reply
  • It Works…thks

    Reply
  • Thank u … This helped me to solve many db problems…

    Reply
  • Thank’s a lot ! It works !!!

    Reply
  • You are my hero…. thanks a lot … just the clue I was looking for… big thanks from Denmark :-)

    Reply
  • subhash choudhary
    July 4, 2012 1:27 pm

    hello please help me . when i going create new new database on server and after create a login than what i req. for this . coz when i m creating a login than this accessing public (any one can access my database when they are login him userid password )

    so please help me what permission require for for database secure ..

    Reply
  • we are having this issue only with sql server 2012, where the login failed user having access if access the database from sql server 2008. Any clue?

    Reply
  • Hi All,

    I am trying to mirror a database. Security Configuration was successful. But the following issue occurs when click the ‘Start Mirroring’.

    ***********************************************************************
    TITLE: Database Properties
    ——————————

    An error occurred while starting mirroring.

    ——————————
    ADDITIONAL INFORMATION:

    Alter failed for Database ‘MyDatabase’. (Microsoft.SqlServer.Smo)

    For help, click:

    ——————————

    An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

    ——————————

    The server network address “TCP://DOMAIN-PC-105:5022” can not be reached or does not exist. Check the network address name and that the ports for the local and remote endpoints are operational. (Microsoft SQL Server, Error: 1418)

    For help, click:

    ——————————
    BUTTONS:

    OK
    ——————————

    *****************************************
    DOMAIN-PC-105 is the Principal server here.

    Anyone has any idea on this.

    Thank you,
    Harsha

    Reply
  • Hai Sir,I got error like this…i need the solution immediately.i am working in private company i need you help…i got this error “Server was unable to process request.cannot open database”smartclassDB”requested by the login.the login failed.login failed for user ‘Sa’.So what’s solution?give your solution to my mail.

    Reply
  • HOW TO REMOVE INSTANCE ID OR CHANGE IT

    Reply
  • pl….. Help…
    primavera 6.0
    xp os
    error:sql server database server

    Reply
  • Please help us on solving same problem while using sql server with Delphi

    Reply
  • its not working :( Cannot open database “stm_cms_db” requested by the login. The login failed.
    Login failed for user ‘XXXXX’.

    Reply
  • Hi Pinal,

    want to send a mail from sql database but getting the same error , pls help

    Reply
  • my code is given below

    EXEC msdb.dbo.sp_send_dbmail
    @profile_name = ‘ACCOUNT1_PROFILE’,
    @recipients = ‘xyz@a.com’,
    @subject = ‘TEST’,
    @body = ‘THIS IS A TEST MESSAGE’,
    @execute_query_database = ‘[MHRL Live DB]’,
    @query = ‘”select * from [MAYAR HEALTH RESORTS LTD_$Membership Member Status] where [Member No_]=TGVVHCT00000003″‘

    error msg

    Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 476
    Query execution failed: Msg 4060, Level 11, State 1, Server MEDISPA, Line 1
    Cannot open database “[MHRL Live DB]” requested by the login. The login failed.
    Msg 18456, Level 14, State 1, Server MEDISPA, Line 1
    Login failed for user ‘NT AUTHORITY\SYSTEM’.
    Msg 0, Level 11, State 0, Line 0
    A severe error occurred on the current command. The results, if any, should be discarded.

    pls advice for the same

    Reply
  • As many others, I don’t have any user called ‘NT AUTHORITY/NETWORK SERVICE’, and when trying to create it I get the following error message:

    “Windows NT user or group ‘NT AUTHORITY\SYSTEM’ not found. Check the name again.”

    Has anyone solved it?

    Reply
  • Thanks a lot. Your solutions are always to the point and specific. Also always solve my problem. I owe you really. Thanks again.

    Reply

Leave a Reply