Devils Work

—Blog By DotNetRuler

Archive for the ‘SQL’ Category

Login Failed For user NetWorkService

Posted by DotnetRuler on January 28, 2009

Hi Friends(Dev’s),

I have been following the Asp.Net Forums from the past one month, and got to know people asking this issue more and more. So i finally decided to put this in my blog along with screen shots for easy understanding purpose.

Problem:  Login failed for user ‘NT AUTHORITYNETWORK SERVICE

Exception Details: System.Data.SqlClient.SqlException: Cannot open database “my_db” requested by the login. The login failed. Login failed for user ‘NT AUTHORITYNETWORK SERVICE.

problem2 

Solution:

The reason why you are seeing this screen is .. When browser requests a page, request goes the IIS (Internet  Information Services). If  the request needs some data from the SQL server IIS tries to access the SQL server With this Access name which dont have credentials to access that particular database. To Resolve this you have to give the permissions for the user to that particular database as follows.

Step1:

Open SQL Server Management Studio and in the left pane below Databases you will see Security. Under Security Section you will see Login. in the subnodes for Login you can see NetworkService User.

step1

What If you dont See that user ?

You need to Right Click on the Login and then Go to NewLogin ==> you will see the below Screen. Click on the Search Button Which will opens another Window.  Click Advanced Button, Which populated another Window called as “Select User Group“. If you click on the “Find Now” it will show all the users available in the Search Results Section. There You will Find the User Network Service. Select it and Clcik ok.

 newlogin1

newlogin2

newlogin4

newlogin5

newlogin6

Step 2:

Once you see the user in the Login Subnodes Right Click on the particular User and go to the Properties. You will see the below Screen.

step3

step4

Step 3:

Then Select UserMapping in the left pane. It will open the Databases that you have in that instance.

step5

Step4:

Check the Database for which you want to give the permissions, in the lower pane you will some roles for that User for that Particular DataBase.  If you check db_owner role for that particular user then you are done.. 🙂

All Comments are appreciated So that i can post my next post t better than this..

Thanks

DotnetRuler

Keep Rocking..\m/

Advertisements

Posted in SQL | Tagged: | 78 Comments »