Monday, August 22, 2011

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

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



0 comments:

Post a Comment