Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Cannot open database requested by the login. The login failed. Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.

Oct 6, 2010
Introduction

Here I will explain about my database connection error in SQL Server if trying to get data by using asp.net.

Description

I have created one database in my Local SQL Server Management Studio in that I created one table and entered some data in that table.


I opened visual studio and created one sample application using asp.net to access the data from the table to achieve this functionality. I written correct code in asp.net and I run application to get data from database at that time I got error like this

Cannot open database "MySamplesDB" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.

For solving this error I have searched so many sites they given variety of answers after check all websites I find common and simple solution that is 

1)    Open SQL Server Management Studio

2)    Login into your server

3)    open your Security in that click on Logins 

          4)  After that Select NT AUTHORITY\NETWORK SERVICE right click on that one go to Properties

From that Login Properties Select User Mappings that is in leftside top .Now you will get list of databases in right side select the databse for which you are getting error after that below of these databases we have a list of Database roles in that check role db_owner and now click ok 

After that check your code now it work perfectly 

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

15 comments :

Anonymous said...

hi thanks for your post it's helps me to solve my problem

Anonymous said...

hi,
could you tell, how to do the same using query and also i'm able to create user for a specific db, however, when i verify under properties, the user is not mapped to dabase

Anonymous said...

Hi Suresh,

Very Urgent...Please
How to store a login values in session and when logout the user session also closed after when browser also closed by the user session will not present on browser.

kotte said...

great

kallurirakesh said...

HAI SURESH please solve the problem in sql server


The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.

Anonymous said...

thanks:D is a small word for such a helpful post.....this post was the perfect ans to my problem

Vivek said...

Hi I am not getting NT AUTHORITY\NETWORK SERVICE,so how i will sorted out same problem,Please help me out for this.

Thanks .
Regards,

Vivek

Veersh Dachepally said...

Hai this is Veeresh
This is My connection String




I am Getting Error

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Vithyasamanavan said...

hi suresh,
Urgent.. please help..

i dont have ssms.

My connection String is

"Data Source=.\SQLEXPRESS; Database=db_name; integrated security=true;"

the error is

"Cannot open database "MySamplesDB" requested by the login. The login failed. Login fialed for the User windows-pc\user"

Anonymous said...

Thanks Man Suresh u r truely a talented guy...
every time i get some problem , u r der with ur post to help me....

Thanx once again

smarty said...

This solution is not working for me. Still I am receiving following error: Cannot open database "dbname" requested by the login. The login failed.
Login failed for user 'Veslap01-PC\Veslap01'

Please help me.
Thank you

sameer said...

hiiii
still i am getting this jWELLERY_DB" requested by the login. The login failed. error

Unknown said...

Hi Suresh ,
My Sql server 2008 don't have "NT AUTHORITY\NETWORK SERVICE" logins name ,
How can solve this problem?

Thanks.....................

Unknown said...

Thank You Suresh

Unknown said...

In my case I'm getting this error with the different user name which I'm no where specified in connection string and I'm getting from where it is getting adda

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.