Login Failed in  ASP.NET

mystar used Ask the Experts™
I have a ASP.NET Web Application program .This program has a connection to a database.When I write this Code(sqlDataAdapter.Fill(dataSett11)) in method Page_Load , And I run program .this Error Occure:
Login failed for user 'ARDESTANI\ASPNET'.
Please Help Me?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Dude.. type in your entire chunk of connection code :-)

And you must make sure of your connection, username and password at your end..

Don't tell us in the end.. oppzz.. password problem.


It looks to me as if you are trying to connect to sql server using the ASPNET account of the web server.  This isn't going to work because the ASPNET account is not a valid SQL login.  

I'm speculating here, but my guess is that your database connection string is set up for "Integrated" security, e.g. "integrated security=SSPI" and your web app is set up for anonymous access.  If this is the case, you have a couple of options:

1.  Configure your web app to run as a domain account which has the necessary Sql Server privileges.  You can do this by first adding the domain account to Sql Server, then using IIS Admin, right click on your web app, click "Directory Security", click "Edit" and set the "Account used for anonymous access" to the domain account.

2.  Change your database connection string to use SQL security, ie. replace "integrated security=SSPI" with
"password=your_password;user id=your_user", where "your_user" is a SQL server account which has the necessary privileges.

If this doesn't help then, as aarontwc mentioned, please post your connection code (but don't include your real userid/password info) and also post the IIS configuration for your ASP app and maybe someone can help.
try using ip address instead of machine name of server in connection string
hope this helps
As Wile said, it sounds like your connection string is set up for Integrated Security, This is fine.

Your problem is that the account 'ARDESTANI\ASPNET' doesnt have access to the database.

The best answer depends on what type solution you are delivering....

Heres my example from some work I was doing....

We have an intranet application where we wanted only authenticated users to access the site and the SQL database and all transactions where to be done under the context of the visiting user.

IIS was installed on one machine and SQL on another. (Pure windows 2000 domain + Active Directory)

Under the authentication section of the config file for the ASP.NET application we had
<authentication mode="Windows"/>
<identity impersonate="true"/>

This ensured that the only authenticated users could access the site, and that the ASP.NET process would assume the identity of the visiting, authenticated user.
(Aka 'ARDESTANI\ASPNET' became 'MyDomain\SomeUser')

At the SQL level we had given "Authenticated Users' permissions to access the database.

If your IIS and SQL was on the same machine, then all would be sweet.
Now since IIS and the SQL server were on DIFFERENT machines, an important setting had to be enabled. Delegation. Delegation basically allows the users (and computers) identity to be passed through to other machines. Delegation can only occur if it is enabled, and IIS is configured to use Windows Authentication.

Enabling Delegation was done through using Active Directory Users and Computers, and modifying the machine group policy to "Allow user accounts to be trusted for delegation" (or something along those lines)

Anyways thats it, now we can use our different security groups to control various access and functionality to the database and only authenticated users have access.

Changing the connection string as Wile said will work but may not be appropriate in your environment.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial