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?
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.
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.
In your web.config file look for
<system.web>
and add:
<identity impersonate="true" />
Check out the following link:
http://msdn.microsoft.com/en-us/library/ms998292.aspx
Hope this helps.
Thanks, Raja
精彩评论