views:

142

answers:

4

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?

+1  A: 

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.

simon_bellis
The user account used by IIS can also be configured. Make sure that account has access to the DB if you'd rather not put the username/password in your connection string.
Frank Schwieterman
@Frank: how to do it please explain..I dont have much experience with IIS.
Akshay
Here's information about what account is used by IIS for anonymous accesss: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/9ded7af2-fcb7-4ed2-b007-e19f971f6e13.mspx?mfr=true
Frank Schwieterman
check this out : http://www.connectionstrings.com/
Myra
A: 

In your web.config file look for

<system.web> 

and add:

<identity impersonate="true" /> 
J.B.
@ J.B : This is not solving the purpose.The same problem persists. LOGIN FAILED.
Akshay
Have you enabled anonymous access in IIS? Try Microsoft's guide:http://support.microsoft.com/kb/324274
J.B.
@ J.B: YES.. anonymous access is enabled.
Akshay
Mind if I see your code?
J.B.
This is the connection string defined in web.config file:<connectionStrings><add name="mail" connectionString="Data Source=HAL; InitialCatalog=mail;Integrated Security=True" providerName="System.Data.SqlClient" /></connectionStrings>I dont mind showing my code, tell me if u want to see something else.
Akshay
A: 

Check out the following link:

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

Hope this helps.

Thanks, Raja

Raja
+1  A: 

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.

Akshay
You should accept an answer !!
Myra