Login fail when accessing data

G

Guest

Hi,

I've come from Forms to web pages. (OH DEAR you say) I'm using VS2003.

When I drag a table from Server explorer onto the web form to create a
DataAdapter & Connection, all ok, but when I try to access that data
programmatically, I get:

System.Data.SqlClient.SqlException: Login failed for user 'mycomputer\ASPNET'.

This is a Login issue no doubt, however, I can Logon to the data base when
working with Windows forms using the same Login & can view data with Server
Explorer.

I don't know IIS too well, but before I plunge into that, is there anybody
who knows what would be the cause of this & how to rectify it?

Any ideas would be most appreciated.

Thanks in advance
Ant
 
T

Tasos Vogiatzoglou

ASP.NET applications run inside ASP.NET worker process (aspnet_wp).
This process is run with a low-privileged user (YOURMACHINE\ASPNET).
The connection you are trying to establish with the SQL Server tries to
use ASPNET credentials and that's why you have the error.

There are 4 alternatives.

1) You enable impersonation, so you can login to SQL Server with your
current credentials. Put in webconfig <identity impersonate="true"/>
2) Enable impersonation with a fixed user account. Put in web.config
<identity userName="username" password="password"/>
3) Change ASPNET user to run with system privileges (altough not
advised as it's a security risk). Go to
c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\config\machine.config,
search for a processModel tag and change the username to system
4) Use a different user for ASP.NET worker process. Again go to the
previous path, in the processModel tag change the username and password
to correspond to your new user.

If you have IIS6 you can setup an application pool with an alternative
user.

Regards,
Tasos
 
G

Guest

Hi Tasos,
Thanks for the prompt reply.

I put

<identity impersonate="true"/>

in the web.config file as this seems the simplest route. I put it directly
under the

<system.web> element, but no go. Is this the correct place to put it? I'm
assuming it doesn't matter. Should this work?

Thanks for your help
Ant
 
K

Kirk Allen Evans

This assumes that the user is authenticated. Do you allow anonymous users?

Still another option in Tasos' list is to add the ASP.NET worker process
account as a user in the database.

Under Windows Server 2003 and IIS6, the user account is determined by the
identity for the application pool. The default is "Network Service", which
is a least-privileged user account. In SQL Server 2005, you can add the
Network Service account as a login and grant that user access to certain
portions of your database. If you are running on Windows XP or 2000 while
developing and testing, you can use the ASPNET account.

--
Kirk Allen Evans
Developer Evangelist
Microsoft Corporation
blogs.msdn.com/kaevans

=== This post provided "AS-IS" with no warranties and confers no rights ===
 
T

Tasos Vogiatzoglou

The user you are logging-in to your PC is the one that will be
authenticated in SQL Server (assuming you have enabled windows
authentication).

So, incase you cannot login, check whether your user has access to the
required database table.

Also, Kirk proposes another solution that would help you (putting
ASPNET as a user to the database) but this as the solutions above
should be handles with care as expose the database to security risks.

Regards,
Tasos
 
G

Guest

Thanks for everyones help. I ended up adding ASP.NET as a user in SQLServer.
It never occured to me that the ASP application was in fact considered a
user. (Different to Windows forms).

Unfortunately I tried adding the reqired elements to my web.config file in
the ASP applications folder <identity etc> but that approach didn't yield any
success. I don't know why.
I also tried to tell the machine.config folder the details needed to log in
but no go either. A little troubling as to why.

Anyway, it's sorted now so thanks very much for your input.

Regards
Ant
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top