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

    Thank so much for this wonderful solution. it has really solved my problem. More blessing and knowledge to u.

    Sale A. A.

    Reply
  • i want to make a data base for school’s result and i want that ,the data base would be seen by the parents but parents can’t change or edit the database ,how can i make my sql data base secure.

    Thanks

    Reply
  • U r the best

    Reply
  • hi
    LOONG WITH THIS helopful aarticle USe one addition thing

    use Integrated Security as “Integrated Security=SSPI” your problem will solved you will not get the same error again ..

    regards

    Reply
  • Thanks again for your article. I can fix this problem after i read this. ^ ^

    Reply
  • I am trying to connect to a database from VS 2008 but am getting the following error:

    Cannot open database “AdventureWorks3” requested by the login. The login failed.
    Login failed for user ‘HpUser_CPUHp User’.
    This website application is stored under:
    c:UsersHp UserDesktopapp2App_DataAdventureWorks3.mdf

    And when I open SSMS I do not see this database listed; just the System databases. But when I try to open this AdventureWorks3 database and navigate to this folder, I do not see this MDF listed. And I have made Administrator, ASP.NET, and Hp User db_owners on the System databases. What else do I need to do to enable this database for VS 2008?

    Reply
  • Now I am trying to add the NETWORK SERVICE login cause I still can’t connect to the AdventureWorks3 database. But I want to add this NETWORK SERVICE login via SQL Server Authentication and not Windows. When I select Windows authentication, it lets me create this login. But when I select SQL Server Auth, it gives me the following error:
    Create failed for Login ‘NT AUTHORITY\NETWORK SERVICE’…’NT AUTHORITY\NETWORK SERVICE’ is not a valid name because it contains invalid characters. (MS SQL Server, Error: 15006)

    Reply
  • Mr. Dave,
    I just want to thank you for this posting this article as well as others. This is the second time in as many days that you have helped me out. You are truly the “SQL Authority”!
    Bruce

    Reply
  • you saved my life!! thank you!

    Reply
  • hi
    this very good but added the basic information about sql server e g how open it and where the work done

    Reply
  • in SQL server 2000>> Security >> Logins …ooops ..there is not such a thing as “NT AUTHORITY\NETWORK SERVICE”,

    also, my application in debug mode works well, when run it in production, this problem appears, I do not why…

    any suggestions? thanx in advance..

    Reply
  • Cannot open database “dating” requested by the login. The login failed.
    Login failed for user ‘sa’.

    now i have read everything you have said up here ..And it is all great and dandy for those who know exactly what they are doing on the pc . I am pretty handy on the pc but there are something I just dont touch . So commands etc are not my thing.. Step by step how to get where and what to click.. yes for us little people out there .. I type the error in to google and get something for everything else.. I am just trying to find out if this is something with my system or what as I just replaced the harddrive and formatted the whole thing.. very frustrating when i start getting errors like this .. if you can help me now that would be great.

    Reply
  • When i am trying to install SQL server 2008 enterprise edition i got the following error.

    CLR error: 80004005
    This program will now terminate

    I am using .NET framework 4.0 on windows 7 64bit. I am in a grate trouble and my machine not allowed me to install any version of SQL server. It would be grate if any one would help me.

    Reply
  • Thanks,

    This was very helpful for me to make my database connection alright.

    Reply
  • Thanks Buddy this was really very helpful to solve my problem.
    Great Job
    Cheers………….

    Reply
  • Works like a charm. Thank you!

    Reply
  • Thanks Man

    Reply
  • thank you

    Reply
  • the great tips, thank you..

    Reply
  • Dear Dave,

    I need you help regarding my sharepoint problem.
    I have read some of your articles and it was really awesome you have solved most of the problems. That’s why i have decided to ask for your assistance.

    First. problem
    Cannot connect to the configuration database.

    I followed one of your comment regarding the security stuff and mappings , unforunately the Config Database of my sharepoint is not listed on the database of my SQL Instance.

    I try to attach the Configuration database so i can assign the priveleges and this is the error i got.

    TITLE: Microsoft SQL Server Management Studio
    ——————————

    Attach database failed for Server ‘thesqlsps’. (Microsoft.SqlServer.Smo)

    For help, click:

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

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

    ——————————

    SQL Server detected a logical consistency-based I/O error: incorrect checksum (expected: 0xb5f67b48; actual: 0xb5f67b58). It occurred during a read of page (1:8670) in database ID 10 at offset 0x000000043bc000 in file ‘C:Program FilesMicrosoft Office Servers14.0DataMSSQL10.SHAREPOINTMSSQLDATASharePoint_Config_fb7bd063-aee7-46ee-880d-e061c3279fb9.mdf’. Additional messages in the SQL Server error log or system event log may provide more detail. This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.
    Could not open new database ‘SharePoint_Config_fb7bd063-aee7-46ee-880d-e061c3279fb9’. CREATE DATABASE is aborted. (Microsoft SQL Server, Error: 824)

    ———

    I tried also using the powershell to run cmdlet commands but still nothing.

    The services of my sharepoint is still running.
    The MDF and LDF files are all intact.
    IIS dont have a problem( I guess)

    Any idea what i’m missing ?
    Thanks in advance.

    Reply

Leave a Reply