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

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.

In almost all such cases, this should fix your problem.
Reference : Pinal Dave (http://blog.sqlauthority.com)










Simple and nice explanation.
Is there any other way around this without having to give db_owner rights? Thanks.
Excellent explanation.
thanks..
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 AUTHORITY\LOCAL 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.
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.
Thanks so much! that helped!
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
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.
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
Thanks! it solve my problem within second that i had debugging the error few days!
Excellent thank you..
Thanks man.. you are the best..
The tip worked like charm..
Dear bro,
This helps me a lot.
Thanx again and again.
Regards,
Sugath
Thanks this helped me a lot
how do i get to the sql server on windows xp? i can only access sql server from sql server configuration manager. Thanks
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
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.
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.
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.
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
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
Hi,
When i open Securit folder i cant see
NT AUTHORITY/NETWORK SERVICE
WHAT CAN I DO?
Thanks
Hi,
The NT AUTHORITY/NETWORK SERVICE account is automatically created if the SQL Server service is run by NT AUTHORITY/NETWORK SERVICE account. Verify that your SQL server service account is different than this account.
Regards,
Pinal Dave
Hi Dave,
I find the thread in this website very helpful, however I have a question about ‘NT AUTHORITY\NETWORK SERVICE’ account, I am getting error “Cannot open database “MyDB.mdf” requested by the login. The login failed. Login failed for user ‘NT AUTHORITY\NETWORK SERVICE’. I have SQL Express 2008 and when I installed it I did not create that account. When I published my website in IIS I am getting that error. Why does my website use ‘NT AUTHORITY\NETWORK SERVICE’. I used windows authentication to login to my Server. My Website worked in Visual Studio. Hope you can help me with this. Thank you
Hi, thanks for the replay
Even on my developement computer there is no NT AUTORITY\NETWORK SERVICE;
MY USERS IS:
BUITLIN\ADMINISTRATOR
BUILTIN\Users
leo
Leonel-PC\SQLServer2005MSSQ
NT AUTORITY\SYSTEM
sa
is there any problem ? cos the System Works well on My computer but on my LAN Server does Not;
i use windows server 2003 sp2;
Is there any script to create this user?
Thanks
Thank you very much.excellent explain.Thanks a lot.
Hello.
And what to do in this case:
Error of connection with a server -1:4060
SQLSTATE = 42000
Microsoft OLE DB Provider for SQL Server
Cannot open database requested in login ‘MASTER’. Login fails.
The result is identical on servers: 2000 SP4/2005/2008
Thanks.
Problem is fixed.
Hi Sir,
Thank U very much
You have saved my day, again :)
Thanks
Wow!!!! after 3 days of trying to find why I keep getting this error:
Cannot open database “” requested by the login. The login failed.
“Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. ”
Exception Details: System.Data.OleDb.OleDbException: Cannot open database “FTF” requested by the login. The login failed.
DID EXACTLY WHAT YOU MENTIONED AND IT WORKED LIKE A CHARM. THANKS YOU SO MUCH !!!
Cen you please explain how you resolved this problem,
Hi people,
my english is not good, but i will try to add something.
my problem was the same, but i couldnt find the NT ACCOUNT,
So i had to create this account and i had to make method the
explained to in this spot.
or try to use this script:
/****** Object: Login [NT AUTHORITY\SYSTEM] Script Date: 03/20/2010 20:43:01 ******/
/****** Object: Login [NT AUTHORITY\SYSTEM] Script Date: 03/20/2010 20:43:01 ******/
CREATE LOGIN [NT AUTHORITY\SYSTEM] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english].
be cool.
Hi Dave,
Hope you can help, I been working on connecting to a MSSQL Database for days, and still can’t solve the problem.
I am developing on Windows 7 64 Notebook.
I need to access (read) a database which is manage by a Commercial Software (say ‘A’), I am able to connect and work with when the Software A is not running, but when Software A is running my application cannot access the Database and vice versa.
The database is set to Multiple_User for Restrict Access. The problem is my application must run when the Software A is running.
I tested it, on its own when in Data Source (ODBC) test or in my application, it works find.
This is my connection string:
MSSQL_Con.ConnectionString = “Data Source=.\SQLEXPRESS;Initial Catalog=” & TheDatabase & “;Integrated Security=SSPI;Trusted_Connection=No; Connect Timeout=30;User ID=AMS;Pwd=88888;”
I had tried Integrated Security – True / False / SSPI
Trusted Connect – True or False
User Instance – Tru / False
it still give me error:
Cannot open database requested by the login. The login failed. Login failed for user ‘User1′
User1 is created in Management Studio and tested OK without Software A.
Please Sir, kindly Help.
Best Regards
Thanks buddy
Sweet, short and clarified.
Thanks :D
saved my life!!!
Hi I am getting below error:
Cannot open database “FTNCorporateAutomation” requested by the login. The login failed.
Login failed for user ‘NAM\at77221’.
this is not specific to NT Athority
Please advise asap.
Thanks
Sandeep
Hello Sanddep,
Please verify login’s access permission in database and Login’s default database. Are you able to connect through other logins or to other datrabases?
Regards,
Pinal Dave
Hi guys
I am getting exactly the same error. This is SQL Server 2000, IIS, ASP web pages, Windows 2000 Server setup. It worked perfectly until we had to restore the whole server due to a virus.
So reformat, reinstall, etc, etc to a brand new (and virus protected) server.
I’ve done everything that I did before, got all the correct permissions, etc and I still get this same error. I’ve done what you suggested above and it does not help. We have ODBC connections which work perfectly, we can access the database through a number of query tools.
What have I missed? I am at my wits end.
Could you make a little test and try to connect to master database with your login credentials? For example,write a little ASP.NET WebForm which connects to master db and tries to read something out of it.
Hi Marko
My problem is that I am not an ASP developer. This program was written a few years ago, and it just chugs along doing it’s thing …. until now. So I have no idea how to do what you are suggesting. I do know that we can connect to the db via ODBC from other pc’s ….
I kind of think that the setup is wrong somehow but don’t know how or even where to look to correct it.
Okay. Then you probably would want to check DB log files. See for entries where Source = Logon. It could be that your web page is not configured properly and it’s trying to connect with wrong credentials.
Oh, and I just notice that you are talking about ASP pages, not ASP.NET. I know almost nothing about ASP so I’m not be able to help you much. Let’s hope the log reveals something enlightening.
Thanks so much!
this article is very help full!
Thanks to you again
i m trying to install SQL Server 2008 enterprise edition and i m getting error =CLR error 80004005 . dont now what to do. i try to change compatibalty still didnt work. plwase help
Hi,
I can’t find ” NT AUTHORITY/NETWORK SERVICE ”
please can you show how can i create this acount
thanks a lot
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.
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
U r the best
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
Thanks again for your article. I can fix this problem after i read this. ^ ^
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_CPU\Hp User’.
This website application is stored under:
c:\Users\Hp User\Desktop\app2\App_Data\AdventureWorks3.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?
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)
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
you saved my life!! thank you!
hi
this very good but added the basic information about sql server e g how open it and where the work done
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..
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.
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.
Did anyone ever solve the CLR Error 80004005 when installing SQL Express 2008 R2?
Thanks,
This was very helpful for me to make my database connection alright.
Thanks Buddy this was really very helpful to solve my problem.
Great Job
Cheers………….
Works like a charm. Thank you!
Thanks Man
thank you
the great tips, thank you..
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: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1600.1+((KJ_RTM).100402-1539+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Attach+database+Server&LinkId=20476
——————————
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 Files\Microsoft Office Servers\14.0\Data\MSSQL10.SHAREPOINT\MSSQL\DATA\SharePoint_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.
Hi again,
I Tried also the Sharepoint 2010 Products Configuration wizard and this is part of the long list of the log file error.
—–
Login failed for user ‘ITLAB\Administrator’.
04/18/2011 04:18:12 8 INF debugMessage for task initialize is An exception of type System.Data.SqlClient.SqlException was thrown. Additional exception information: Cannot open database “SharePoint_Config_fb7bd063-aee7-46ee-880d-e061c3279fb9″ requested by the login. The login failed.
Login failed for user ‘ITLAB\Administrator’.
System.Data.SqlClient.SqlException: Cannot open database “SharePoint_Config_fb7bd063-aee7-46ee-880d-e061c3279fb9″ requested by the login. The login failed.
Login failed for user ‘ITLAB\Administrator’.
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.SharePoint.Utilities.SqlSession.OpenConnection()
at Microsoft.SharePoint.Utilities.SqlSession.ExecuteReader(SqlCommand command, CommandBehavior behavior, SqlQueryData monitoringData, Boolean retryForDeadLock)
at Microsoft.SharePoint.Utilities.SqlSession.ExecuteReader(SqlCommand command, Boolean retryForDeadLock)
at Microsoft.SharePoint.Utilities.SqlSession.ExecuteReader(SqlCommand command)
at Microsoft.SharePoint.Administration.SPLock.ReleaseStaleLock(SqlSession sqlsession, Int32 timeoutInSeconds)
at Microsoft.SharePoint.Administration.SPLock.CleanupStaleSession()
at Microsoft.SharePoint.Upgrade.SPManager.AcquireFarmUpgradeLock(Boolean bForce, Boolean singleClickInstall)
at Microsoft.SharePoint.PostSetupConfiguration.InitializeTask.Run()
at Microsoft.SharePoint.PostSetupConfiguration.TaskThread.ExecuteTask()
——
Thanks again in advance
System.Data.SqlClient.SqlException: Cannot open database “Sports” requested by the login. The login failed.
Login failed for user ‘TUSHAR\DP’.
i will doing all changes u declard above but this error will occurd. plz tell me the solution.
thank u.
i wiil post my codng line below:
{
SqlConnection conn = new SqlConnection(“Data Source=Tushar\\SQLEXPRESS;Initial Catalog=Sports;Integrated Security=True;uid=tusharsim;Password=tusharsim”);
}
web.config code is:
plz help me
This solutions works perfect.
Thanks a lot for saving a couple of my hours.
Keep the good work going.
Thanks a lot…
This solutions works perfect.
Thanks a lot……
perfect site for solution ….
im geeting the following error
Cannot open database “userdatabase” requested by the login. The login failed.
Login failed for user ‘DOTNET1\ASPNET’.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot open database “userdatabase” requested by the login. The login failed.
Login failed for user ‘DOTNET1\ASPNET’.
i tried the above but it did’nt help ,the problem is im able to run on my local machine but not on shared network
my connection string in web .config is above:-
please help me out .
May tell me about this messages :
- SHUTDOWN is in progress. Login failed for user ‘xxx’. Only
administrators may connect at this time.
- Cannot open database “SignOnDB” requested by the login. The
login failed. Login failed for user ‘xxx’.
I’m using sqlserver 2005 in that i don’t have option like NTAuthority/network service what shall i do I’m getting this error
Server Error in ‘/sam’ Application.
——————————————————————————–
Cannot open database “karthik” requested by the login. The login failed.
Login failed for user ‘HOME-91ECE83970\ASPNET’.
HI,
Can you help me, i installed primavera in my pc but i cannot open any files on it, it happens only after i imported another file, previously it was okay until i did the last importing. Is there any connection with the sql server regarding this problem. I checked the database it says that database pmdb$primavera is not accessible ( microsoft.SQL server. Express. Object explorer) . Please help. Thank you
Hello Dave, I get this error message in my log when attempting to run the config wizard in sharepoint 2010:
Failed to connect to the database, and this is in the log.
A System.Data.SqlClient.SqlException was thrown on server sqlxxx, database master
SQL Server will NOT LET ME create a login for IIS APPPOOL\ASP.NET v4.0!!! Please help. I try and try but keep getting this error: “Windows NT user or group IIS APPPOOL\ASP.NET v4.0 not found. aaarrgghhh!!!
You are my Hero!!! Thanks for solution :D
good blog sir It works thanks.
Excellent man.. im grateful to you, you saved my time. thanks..
Hello All of u,
My problem is “Microsoft OLE DB Provider for SQL Server error ’80040e4d’
Login failed for user ‘NT AUTHORITY\ANONYMOUS LOGON’ “i had tried first example of pinal to resolve it,then also,i am on same problem.
Please help me out,
Thanks in advance
Jayanti
Hi,
This is ram,i want to study asp.net will u pls refer me some sites for learning easily with practical approach
mail me [email removed]
If you want to learn asp.net visit this site http://www.asp.net You can find lot code exmaples there
Thank you very much, it solved my problem.
I read the first few lines of this writeup and started smiling .. and it worked fine. thanks!
Thanks – I must say you are the “man” and have helped me out a lot …
Thank you so much! I google for problem solution often and have ended up in your site and found the right solution quite a few times. Kudo to you!
Thanx buudy. That solved my problem.
Thanx!! my prob has been solved.
Sir I want To access Master Database Table Through Asp.net
Pls Help Me
Thanks In advance
Have a connection string that points to Master database in your application
Hi pinal,
This is Rashmi.I am getting following error some times and not regularly.
Cannot open database “xyz” requested by the login. The login failed.
Login failed for user ‘xyz ‘.
Please Help me…
Hi, Mr. Pinal
This is Rahul. And my problem is that
A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 – An established connection was aborted by the software in your host machine.) (Microsoft SQL Server, Error: 10053)
This problem is occured when i connect to SQLEXPRESS.
Please help me out.
Regards
Rahul Singh
your initial solution resolved my issue I was having after I restored my database from SQL 2000 to SQL 2005 server. Thank you.
I stumbled upon this while doing many searches. What is the main link to this blog?
Hey., i have trouble in logging to Primavera the error is “Bad public user name or password. Database Server Error: Encryption not supported on the client”.
Kindly help
thanks alot
I don’t have NT AUTHORITY\NETWORK SERVICE. :( only the NT AUTHORITY\LOCAL SERVICE
Please help. thanks in advance. :)
thankyou
I like u r blog,answer is very straight forward,but still i got problem.this one different ‘ANGELICA-D45444\ASPNET’.
I don’t have NT AUTHORITY\NETWORK SERVICE. :( only the NT AUTHORITY\LOCAL SERVICE
Please help. thanks in advance. :)