Web forms and data access

  • Thread starter Thread starter Ed B
  • Start date Start date
E

Ed B

I've been trying to connect to SQL Server 2000 through a web form created in
c#. As I created my connection object the data source test succeeded. I've
even tried the datapage wizard and I get the following message:



Login failed for user '\'.



I can successfully connect when creating a Windows application, just not
from a web form app.

Can anyone help? Thanks
 
Ed,

The reason for this is that by default, ASP.NET runs under the local
ASPNET user account. This account doesn't have any rights to the network,
and I imagine that is the problem.

In order to get around this, you will have to change the user that this
page runs under (or even the operation). You have three options:

- Elevate the rights of the ASPNET user so that it can access the database
(not a preferred option).

- Change the user that the web app runs under (through the web.config file)
so that it runs under a user that has rights. You have to be careful
though, because all pages in the directory that the web.config file is in
will run under that user context.

- Imitate the user. Check the documentation for the Impersonate method on
the WindowsIdentity class to see how you can impersonate a user at will.

Hope this helps.
 
Back
Top