Asp.net - When I run my website on IIS, Database login fails

3.4k Views Asked by At

In my website I am accessing my sqlserver database using "windows authencation mode". Everything works fine when I run my website using visual studio. but when I hosted my website on IIS, everytime an error message comes that "database login failed".

Login failed for user 'HAL\IUSR_HAL'.(HAL is the name of my webserver)

Should I do some modifications in database properties so that I can login to database through IIS?

4

There are 4 best solutions below

0
Akshay On BEST ANSWER

After some research i got the answer of this question.

To access the database through a website running on IIS , IIS's IUSR account and ASPNET account should be authenticated and authorized to sqlserver.

(ASPNET account is the account of dotnet framework associated with IIS to process asp.net pages.)

to do this:

open Sqlserver management studio. go to SECURITY. then right click on LOGIN and select "new login". press "search" on login name. then click "advanced" button. Then press "find now" button. then from list appeared select both of the accounts mentioned above.(one at a time) then press ok. after selecting the login name go to it's "user mappings" options. then select the database from there and check the desired permissions.

now you are done with everything. press ok.

you can access database from ur website.

3
bristows On

If your using anonymous access in IIS you will need to supply a user id and password for a valid sql user in your connection string.

4
J.B. On

In your web.config file look for

<system.web> 

and add:

<identity impersonate="true" /> 
0
Raja On

Check out the following link:

http://msdn.microsoft.com/en-us/library/ms998292.aspx

Hope this helps.

Thanks, Raja