473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Login fail when accessing data

Ant
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

May 30 '06 #1
5 1200
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\confi g\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

May 30 '06 #2
Ant
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

"Tasos Vogiatzoglou" wrote:
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\confi g\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

May 30 '06 #3
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 ===
"Ant" <An*@discussions.microsoft.com> wrote in message
news:88**********************************@microsof t.com...
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

"Tasos Vogiatzoglou" wrote:
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\confi g\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


May 30 '06 #4
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

May 30 '06 #5
Ant
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
"Tasos Vogiatzoglou" wrote:
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

May 30 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: fl | last post by:
I am running ASPNET on my local machine. I have a problem when I try to connect to a SQL server database table. The data looks good when I right click SqlDataAdapter1 to preview the data. When F5...
2
by: pv | last post by:
Hi everyone, I need help with following scenario, please: Users are accessing same web server from intranet (users previously authenticated in Active Dir) and from extranet (common public...
18
by: Gleep | last post by:
I've searched google intensely on this topic and it seems noone really knows how to approch this. The goal I don't want clients to give out their usernames and passwords to friends, since the site...
3
by: bull1099 | last post by:
I designed a simple site which has a login for users to access their account page. When i had my files uploaded on a terrible hosting service site, my website I designed was fully functional. I moved...
2
by: nehas | last post by:
Hi I am developing a site using PHP and mysql . I am really new to it.Now I have a problem that I have build up a login page . Before accessing any of the web pages on my site first user should login...
5
by: muppetjones | last post by:
I'm really new to the whole networking side of things, so I don't know the backend very well. I wrote a series of PHP/AJAX scripts to allow a user to create a login account, but apparently my script...
0
by: DanWeaver | last post by:
Using asp and SQLserver2005 on shared server and with connection string: <connectionStrings> <remove name="LocalSqlServer"/> <add name="LocalSqlServer" connectionString="Data...
4
by: Brett | last post by:
I have an ASP.NET 2.0 application that uses Forms Authentication. The startup page contains just a login control, and the site works well on an IIS 6 web server. I am now setting the site up on...
5
by: mcfly1204 | last post by:
I am attempting to use WebRequest to access a page that requires a login/password to access. My last WebRequest continues to timeout. Any help or thoughts would be appreciated. namespace...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.