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

  • Gangadhar Naidu
    August 20, 2009 11:34 am

    Simple and nice explanation.

    Reply
  • Is there any other way around this without having to give db_owner rights? Thanks.

    Reply
  • Excellent explanation.
    thanks..

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

    Reply
    • Easiest is to just delete and recreate that SSP if you don’t have any real affinity for that database. You’ll need a domain service account to create it – you can’t use the network service because you have to type in a password when recreating the web application database.

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

    Reply
  • Thanks so much! that helped!

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

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

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

    Reply
  • Thanks! it solve my problem within second that i had debugging the error few days!

    Reply
  • Excellent thank you..

    Reply
  • Thanks man.. you are the best..
    The tip worked like charm..

    Reply
  • Dear bro,

    This helps me a lot.

    Thanx again and again.

    Regards,
    Sugath

    Reply
  • Thanks this helped me a lot

    Reply
  • how do i get to the sql server on windows xp? i can only access sql server from sql server configuration manager. Thanks

    Reply
  • Hello Budoman

    Your question is not clear to me. Do you want to see the SQL Server services in windows xp? please clariy.

    Regards,
    Pinal Dave

    Reply
    • Hi Pinal Dave:

      I downloaded Microsoft SQL Server Management Studio Express and did as you instructed here but I am still getting the following error:

      Cannot open database “AdventureWorksLT” requested by the login. The login failed. Login failed for user

      Thanks.

      Reply
  • Here i tried this one but still i got error that i listed below.

    I got this error :-
    Runtime error 2147467259(80004005)
    can not open database security requested by the login. the login failed.

    In that i have one setup file received from client and i have no code of it. It is windows application and uses a database sql server 2000.

    At the starting page of software it asks about connection string . And i put in it and connection succed it also shows. After it the login page open and there i enter Id and password which are given by client. But got this upper error.
    I tried almost everything and I also tried upper things that u r suggested but still no problem solved. So pls as soon as possible give me some slution of that.
    I heard lots of about you and i also attained yr seminar located at ahmedabad. so pls give me some help
    Thanks & Regards,
    Ravi.

    Reply
  • Hello ,
    I asked you one problem. Is anything finding you? If not then pls try it. And also allow it on your this question blog so others can answer also.

    Reply
  • Hi there,
    Thank you very much , your answer is simple and effective.I was struggling for hours on this issue and your suggestions worked in seconds.
    Many Thanks,
    Ajit

    Reply
  • This is actually a very bad practice, since many other processes run as Network service.
    All you have to do to properly take care of this is create a new App Pool (Under IIS mmc console, go under app pools) , and right-click, go to properties, then Identity, set it to Configurable, and set the login which has permissions for the databases you’re getting errors for.
    Don’t forget to go to web site properties and change the app pool to the new one you created.

    TK

    Reply
    • You are a genius. I have been trying to solve this problem for over a year now on a particular server, had all but given up – there are literally hundreds of different solutions offered on the web but none worked for me until I read your solution. Brilliant, I am very grateful to you!

      Reply

Leave a Reply