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 Dave,

    I have a similar issue here.

    I have 2 instance, A and B. On instance A, in order to let a job access and manipulate data in a database on instance B, a linked server is created. Linked server connection test is successful and from instance A I can even open a new query and retrieve data on instance B. But the job failed with an error: “Login failed for user ‘login_name'”, “Cannot open database “xxx” requested by the login.” The interesting thing here is the ‘login_name’ is not the owner of the job. I set a sysadmin login as the job owner.

    I tried to use your recommendation in this article, but when I open the property of the job owner, I couldn’t find the database on instance B because it is showing only the local databases. Do you think I can do the same configuration under a cross instance environment? I appreciate your time and support. I look forward to your reply. Thanks.

    regards,

    Oliver

    Reply
    • Sorry, I think I need to correct something I’ve said. In instance B, if we open a login property, we can map the login to a database in instance A. However, even if I make the change, I still get the same error. I’m wondering whether we need to change the job owner on instance A to fix the issue. Thanks

      Reply
  • natural remedies for toothache
    November 28, 2012 8:13 pm

    Can I simply just say what a relief to uncover someone
    who genuinely understands what they’re talking about on the internet. You certainly realize how to bring a problem to light and make it important. A lot more people have to read this and understand this side of the story. I can’t believe
    you’re not more popular since you surely possess the gift.

    Reply
  • Thank you soo much… Your are soo much geniuos….

    Reply
  • Thank you very very very much for this article….. :)…

    Reply
  • Hi Pinale,

    From my asp.net application , when trying to connect to sql server 2008 i am getting the error “cannot open database “prgndb” requested by the login. The login failed.login failed for the user “prg””. But i am able to connect to database from my sql server. From my asp.net when i am trying to connect to sql server 2008 i got the above error. Please help me……….

    Reply
  • Hi Pinale,

    From my asp.net application , when trying to connect to sql server 2008 i am getting the error “cannot open database “prgndb” requested by the login. The login failed.login failed for the user “prg””. But i am able to connect to database from my sql server. From my asp.net when i am trying to connect to sql server 2008 i got the above error. Please help me……….

    Reply
  • Hi, thank you so much! Simple and easy. :D

    Reply
  • i just can say thank you so much.your way was successful.i tried many of ways but they didn’t get work.
    thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks

    Reply
  • Please help me to correct this error “HRESULT E_FAIL has been returned from a call to a COM component” . It occurs when I brows the cube in visual studio 2008.

    Reply
  • Many Many thanks for your great help.
    Tara

    Reply
  • hi , i am getting an error when i changed the server, even though my connection string correct. the error is = The supplied connection string is not valid, because it contains insufficient mapping or metadata information.

    Reply
  • The supplied connection string is not valid, because it contains insufficient mapping or metadata information. do u know what it means?

    Reply
  • my problem is fixed. Thank u so much !

    Reply
  • Hi Pinal Dave,

    In the Login Properties screen, i can’t locate the database that appear in the error message. So what should i do next?

    Reply
  • Pinal, you are the best!!!!!…please provide some performance tuning solution, like…long running query. Also SQL Server Performance Counter guidance.

    Thanks Sumi

    Reply
  • Zainab Kachkach
    May 3, 2013 2:18 pm

    You made my day ,effffffffffffffffffffffffffffffff thank you so much

    Reply
  • I cannot see my database in the list of databases to be selected

    Reply
  • i am getting the same error ..
    i am using code first method for creating DB.

    Reply
  • Hi..i got the same problem in.. i’m new in asp.net and sql server.. i need to deploy a website in sql server.. how ever, i cannot do insert operation to my website..the error showing is ‘login fair for nt\authority system’..i go through this article and other article.. i still cannot fix my problem..please help me

    Reply
  • Mahad Abshir
    July 25, 2013 5:24 pm

    Hi, i got a similar problem but it involves a different user, i followed the steps but the same error occured. “Cannot open database “HMS_Data” requested by the login. The login failed.
    Login failed for user ‘MIGIDDY-MAC\sharmake’.” is there any other way to solve this error

    Reply

Leave a Reply