473,394 Members | 1,956 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,394 software developers and data experts.

Login Fails for SQL Server from Web Service

Coy
I've added the ASPNET user to my local SQL Server 2000,
but I still get an unhandled exception: Login failed for
user 'C594891-A\ASPNET'. This is when using a web
service. A similiar ASP.NET application works perfectly
fine, even before I gave any access to the ASPNET account.

I read KB article 316989. In SQL Server 2000, I've added
a login, dbaccess, and granted full rights to the
'C594891-A\ASPNET user. This doesn't make any difference.
The article describes an aspnet_wp "security context" or
account. There is no such account, and SQL Server can't
do anything about any secuity context. Since you can't use
ASPNET to log onto XP, I haven't tested queries in the
database, but I did added the same rights to another account
and when I log on with Windows Integrated security and start
Query Analyzer, that account can do anything in the database.
Anyway, the failure is at login, so I'm guessing web services
need something different to pass the login, than ASPNET
applications require.

The web.config files are the same for the web service, as
for the ASP.NET application. Both are IIS applications.
The application displays data fine, but the web service can't
even log on. Is there a way to trace how IIS is handling the
request.

Below are the non-vanilla portions of the web.config.
<appSettings>
<add key="ConnectString"
value="Server=(local);Database=nes;Trusted_Connec tion=Yes"></add>
</appSettings>
<authentication mode="Windows" />

Thanks


Nov 18 '05 #1
8 2355
Don't use Trusted Connection.

Instead use usual SQL connection string used to access SQL
Server :
<add key="ConnectString"
value="Server=(local);Database=nes;user id=C594891-
A\ASPNET;password='xxx';database=xxxx"></add>

Hope this helps :)

Jody Ananda
MCAD.NET,MCSD.NET
"All programs are poems, it just not all programmers are
poets."

-----Original Message-----
I've added the ASPNET user to my local SQL Server 2000,
but I still get an unhandled exception: Login failed for
user 'C594891-A\ASPNET'. This is when using a web
service. A similiar ASP.NET application works perfectly
fine, even before I gave any access to the ASPNET account.

I read KB article 316989. In SQL Server 2000, I've added
a login, dbaccess, and granted full rights to the
'C594891-A\ASPNET user. This doesn't make any difference.
The article describes an aspnet_wp "security context" or
account. There is no such account, and SQL Server can't
do anything about any secuity context. Since you can't useASPNET to log onto XP, I haven't tested queries in the
database, but I did added the same rights to another accountand when I log on with Windows Integrated security and startQuery Analyzer, that account can do anything in the database.Anyway, the failure is at login, so I'm guessing web servicesneed something different to pass the login, than ASPNET
applications require.

The web.config files are the same for the web service, as
for the ASP.NET application. Both are IIS applications.
The application displays data fine, but the web service can'teven log on. Is there a way to trace how IIS is handling therequest.

Below are the non-vanilla portions of the web.config.
<appSettings>
<add key="ConnectString"
value="Server= (local);Database=nes;Trusted_Connection=Yes"></add></appSettings>
<authentication mode="Windows" />

Thanks


.

Nov 18 '05 #2
Coy,
Try using "Integrated Security=SSPI" rather than "Trusted_Connection=Yes".
http://www.able-consulting.com/dotne...anagedProvider

Also, if you really want the calling User's credititals to be used,
rather than the ASP..NET's work processs credititals, then make sure
to add a <identity impersonate="true" /> to your web.config file.

You can run a SQL Profiler (Start | All Programs | Microsoft SQL Server |
Profiler) to see what which user is connecting, and what SQL commands
are being passed in. A very handy debugging tool!
http://msdn.microsoft.com/library/de..._perf_86ib.asp

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP

Hire top-notch developers at
http://www.able-consulting.com
Coy wrote:
I've added the ASPNET user to my local SQL Server 2000,
but I still get an unhandled exception: Login failed for
user 'C594891-A\ASPNET'. This is when using a web
service. A similiar ASP.NET application works perfectly
fine, even before I gave any access to the ASPNET account.

I read KB article 316989. In SQL Server 2000, I've added
a login, dbaccess, and granted full rights to the
'C594891-A\ASPNET user. This doesn't make any difference.
The article describes an aspnet_wp "security context" or
account. There is no such account, and SQL Server can't
do anything about any secuity context. Since you can't use
ASPNET to log onto XP, I haven't tested queries in the
database, but I did added the same rights to another account
and when I log on with Windows Integrated security and start
Query Analyzer, that account can do anything in the database.
Anyway, the failure is at login, so I'm guessing web services
need something different to pass the login, than ASPNET
applications require.

The web.config files are the same for the web service, as
for the ASP.NET application. Both are IIS applications.
The application displays data fine, but the web service can't
even log on. Is there a way to trace how IIS is handling the
request.

Below are the non-vanilla portions of the web.config.
<appSettings>
<add key="ConnectString"
value="Server=(local);Database=nes;Trusted_Connec tion=Yes"></add>
</appSettings>
<authentication mode="Windows" />


Nov 18 '05 #3
Coy
Okay,
with <identity impersonate="true" /> I see my data. However,
I find that it is impersonating me, not the ASPNET account.
This implementation is a Windows Forms application reaching
out to a Web Service. I want all incoming requests to impersonate
the same Windows NT account. I thought ASPNET was going to
be that account, but I thought wrong. Anyway, I don't want the
name and password of such an account to be in the web.config
as that seems sloppy and old fashioned. I guess I need to find out
how the ASP.NET role based security works and try to set that up.
Thanks for your help.
"Carl Prothman [MVP]" <ca****@spamcop.net> wrote in message
news:er**************@TK2MSFTNGP12.phx.gbl...
Coy,
Try using "Integrated Security=SSPI" rather than "Trusted_Connection=Yes".
http://www.able-consulting.com/dotne...m#SQLClientMan
agedProvider
Also, if you really want the calling User's credititals to be used,
rather than the ASP..NET's work processs credititals, then make sure
to add a <identity impersonate="true" /> to your web.config file.

You can run a SQL Profiler (Start | All Programs | Microsoft SQL Server |
Profiler) to see what which user is connecting, and what SQL commands
are being passed in. A very handy debugging tool!
http://msdn.microsoft.com/library/de...us/adminsql/ad
_mon_perf_86ib.asp
--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP

Hire top-notch developers at
http://www.able-consulting.com
Coy wrote:
I've added the ASPNET user to my local SQL Server 2000,
but I still get an unhandled exception: Login failed for
user 'C594891-A\ASPNET'. This is when using a web
service. A similiar ASP.NET application works perfectly
fine, even before I gave any access to the ASPNET account.

I read KB article 316989. In SQL Server 2000, I've added
a login, dbaccess, and granted full rights to the
'C594891-A\ASPNET user. This doesn't make any difference.
The article describes an aspnet_wp "security context" or
account. There is no such account, and SQL Server can't
do anything about any secuity context. Since you can't use
ASPNET to log onto XP, I haven't tested queries in the
database, but I did added the same rights to another account
and when I log on with Windows Integrated security and start
Query Analyzer, that account can do anything in the database.
Anyway, the failure is at login, so I'm guessing web services
need something different to pass the login, than ASPNET
applications require.

The web.config files are the same for the web service, as
for the ASP.NET application. Both are IIS applications.
The application displays data fine, but the web service can't
even log on. Is there a way to trace how IIS is handling the
request.

Below are the non-vanilla portions of the web.config.
<appSettings>
<add key="ConnectString"
value="Server=(local);Database=nes;Trusted_Connec tion=Yes"></add>
</appSettings>
<authentication mode="Windows" />


Nov 18 '05 #4
Coy wrote:
Okay,
with <identity impersonate="true" /> I see my data. However,
I find that it is impersonating me, not the ASPNET account.

That is what impersonate="true" means... ;-)
This implementation is a Windows Forms application reaching
out to a Web Service.
I want all incoming requests to impersonate

the same Windows NT account. I thought ASPNET was going to
be that account, but I thought wrong. Anyway, I don't want the
name and password of such an account to be in the web.config
as that seems sloppy and old fashioned.


With Anonymous Authentication enabled for a Web Service web site,
and authentication mode set to Windows with impersonate set to false
in the web.config file, I was able to have the ASPNET account
(on Windows XP) and NT AUTHORITY\NETWORK SERVICE (on
Windows Server 2003) be able to select data from the Northwind database
after adding the corresponding account as SQL Server users and giving
the account read rights to the Northwind database.

Are you sure you the ASPNET user account is being used? Try adding the
following code to your web service, then step through and see which account
is being used.
Dim username As String = WindowsIdentity.GetCurrent().Name

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP

Hire top-notch developers at
http://www.able-consulting.com
Nov 18 '05 #5
Carl Prothman [MVP] wrote:
Are you sure the ASPNET user account is being used? Try adding
the following code to your web service, then step through and see
which account is being used.
Dim username As String = WindowsIdentity.GetCurrent().Name


Also, exactly how did you add the account as a SQL Server user with
permissions to the database?

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP

Hire top-notch developers at
http://www.able-consulting.com
Nov 18 '05 #6
> Coy wrote:
Carl Prothman [MVP] wrote:
Also, exactly how did you add the account as a SQL Server user with
permissions to the database?
Adding the required access to use a SQL server database
requires 3 steps:


Did you add the user account to SQL Server first?
e.g. sp_addlogin
use Tunes
exec sp_grantlogin 'C594891-A\ASPNET

Also call "sp_defaultdb" and "sp_defaultlanguage"
e.g.
exec sp_defaultdb N'CARL20\ASPNET', N'Northwind'
exec sp_defaultlanguage N'CARL20\ASPNET', N'us_english'

Make sure NOT to give the user account access to the "master"
database (for the default database).
use Tunes
exec sp_grantdbaccess 'C594891-A\ASPNET'

Isn't that
EXEC sp_grantdbaccess N'CARL20\ASPNET', N'ASPNET'
use Tunes
Grant select, insert, delete on Tunes to 'C594891-A\ASPNET'

Typically you grant execute permissions on stored procedures
and not on tables.
I no longer think it is a good idea to grant any database
access specifically to ASPNET, since ASPNET is
effectively the anonymous account. This means I've
actually invited all anonymous users into my database.

I agree, but if you only give exec permissions to selected
Stored Procedures, it should be fine.
Also, I shouldn't be using Windows authentication for
Internet users, since they obviously don't have domain
accounts. I think I can either use basic authentication
over SSL

Basic Auth still validates against a Domain acccount.
or possibly Passport - whatever I can do
when I don't control or provide the client interface
that is contacting my web service. No much change
here since the days of ASP?

Next I need to see if it is a good idea to impersonate
some domain account for the database access. I would
need to log on previously authenticated users as that
domain account. I'd set up database access for that account
instead of ASPNET. However, I'm also not sure how to
log on a user programmatically from inside a web service
in order to use that strategy.


If you truly need Anonymous Authentication (which it sounds like you do),
then I would keep Anonymous Authentication enabled on on the Web Service
web site and use either:

1) Use a trusted connection string and impersonate a user account which has access
to the database and it's username/password is stored in the system registery for
secuirty reasons:
e.g.
<configuration>
<system.web>
<identity>
userName="registry:HKLM\Software\AspNetIdentity,Na me"
password="registry:HKLM\Software\AspNetIdentity,Pw d"
</identity>
</system.web>
</configuration>
http://msdn.microsoft.com/library/en...itysection.asp

2) Or use a standard SQL Server username / connection string. You can encrypt
the SQL Server username and password if you like.
http://msdn.microsoft.com/library/en.../html/daag.asp
- See section "Storing Connection Strings"

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP

Hire top-notch developers at
http://www.able-consulting.com
Nov 18 '05 #7
Coy
We never use sp_addlogin these days, its for SQL Server
authentication only. That's a high maintenance login since
you have to create and maintain it on every server every
time a password needs to change.
http://msdn.microsoft.com/library/de...us/tsqlref/ts_
sp_adda_0q7i.asp

Therefore you can see that while you're using
<authentication mode="Windows" />
such a login is never interrogated.

Anyway, you can do:
exec sp_helplogins on any machine around you and see that
the domain ASPNET account has already been installed by
the Visual Studio setup. Master is its default database. So
you don't have to add any login for it, at least on development
machines.

Since you're not doing any authentication and ASPNET has
sufficient access permissions you haven't done anything we
all haven't done. For a web service, obviously the database
login will be deliberate, and the granted permissions strict.
IIS won't be set to anonymous for me. I'm flipping through
MSDN magazine to see which authentication implementations
have the Redmond seal of approval. I'll make my points
here later in the week.

I'm saving all your other points on the database setup:
Also call "sp_defaultdb" and "sp_defaultlanguage"
e.g.
exec sp_defaultdb N'CARL20\ASPNET', N'Northwind'
exec sp_defaultlanguage N'CARL20\ASPNET', N'us_english'

Make sure NOT to give the user account access to the "master"
database (for the default database).

Typically you grant execute permissions on stored procedures
and not on tables.
I don't get use any N's in Query Analyser. I guess that's essential for
enforcing wide character strings under .NET when programmatically
building strings for queries.
I no longer think it is a good idea to grant any database
access specifically to ASPNET, since ASPNET is
effectively the anonymous account. This means I've
actually invited all anonymous users into my database. I agree, but if you only give exec permissions to selected
Stored Procedures, it should be fine. I like the idea of using sp_addrole and sp_addrolemember
to manage permissions for a set of role members.
Also, I shouldn't be using Windows authentication for
Internet users, since they obviously don't have domain
accounts. I think I can either use basic authentication
over SSL Basic Auth still validates against a Domain acccount. Yes, I overlooked this. However, the username and
password can also be validated by other means.
If you truly need Anonymous Authentication (which it sounds like you do),
then I would keep Anonymous Authentication enabled on on the Web Service
web site and use either: No I don't want Anonymous, I will present a login screen as
soon as necessary.
1) Use a trusted connection string and impersonate a user account which has access to the database and it's username/password is stored in the system registery for secuirty reasons:
e.g.
<configuration>
<system.web>
<identity>
userName="registry:HKLM\Software\AspNetIdentity,Na me"
password="registry:HKLM\Software\AspNetIdentity,Pw d"
</identity>
</system.web>
</configuration>
http://msdn.microsoft.com/library/en...ntitysection.a
sp
2) Or use a standard SQL Server username / connection string. You can encrypt the SQL Server username and password if you like.
http://msdn.microsoft.com/library/en.../html/daag.asp
- See section "Storing Connection Strings"

I'll go read about this and similar topics.

Thanks
Nov 18 '05 #8
Coy
How could the error message text from the
database driver be wrong?

I added that code anyway. However I don't know
how to break in the web service when I start from
a windows forms client on the same machine. Therefore
I don't get to see the assignment. I suppose I should
just trace it instead of breaking, but I haven't done
so as yet. Anyway, I need to set IIS away from
anonymous before that code runs. I'll try Passport,
Basic and other authentication. Right now, when
I debug the web service directly, the principal is
me, but of course that is a bogus test.

Thanks

"Carl Prothman [MVP]" <ca****@spamcop.net> wrote in message
news:O7**************@TK2MSFTNGP09.phx.gbl...
Coy wrote:
Okay,
with <identity impersonate="true" /> I see my data. However,
I find that it is impersonating me, not the ASPNET account.

That is what impersonate="true" means... ;-)
This implementation is a Windows Forms application reaching
out to a Web Service.
I want all incoming requests to impersonate

the same Windows NT account. I thought ASPNET was going to
be that account, but I thought wrong. Anyway, I don't want the
name and password of such an account to be in the web.config
as that seems sloppy and old fashioned.


With Anonymous Authentication enabled for a Web Service web site,
and authentication mode set to Windows with impersonate set to false
in the web.config file, I was able to have the ASPNET account
(on Windows XP) and NT AUTHORITY\NETWORK SERVICE (on
Windows Server 2003) be able to select data from the Northwind database
after adding the corresponding account as SQL Server users and giving
the account read rights to the Northwind database.

Are you sure you the ASPNET user account is being used? Try adding the
following code to your web service, then step through and see which

account is being used.
Dim username As String = WindowsIdentity.GetCurrent().Name

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP

Hire top-notch developers at
http://www.able-consulting.com

Nov 18 '05 #9

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

Similar topics

0
by: Mr.KisS | last post by:
Hello. I'm under Windows XP PRO SP1, IIS 5.1 ans SQL SERVER 2005 Express. When i try to open a connexion with : <connectionStrings> <add name="AppCnxStr"...
2
by: Mr.KisS | last post by:
Hello. I'm under Windows XP PRO SP1, IIS 5.1 ans SQL SERVER 2005 Express. When i try to open a connexion with : <connectionStrings> <add name="AppCnxStr"...
2
by: pvl | last post by:
Hi We have the following scenario: 1. SQL server 2000 on Windows 2003 Server 2. Web server 1, running web service 1 on Windows 2003 Server 3. Web server 2, running web service 2 on Windows 2000...
3
by: Evan Camilleri | last post by:
I have a problem for a Windows Service to login on an SQL server (different machine) - neither Windows Authentication nor SQL Authentication worked. LOGIN FAILED FOR USER sa (for example). If...
1
by: beachboy | last post by:
how can pass the login (security info) to secondary application? ASP.NET 1.1 user login to application 1(app1.myapp.com) with their username and password, then they have a link to application 2...
0
by: sh | last post by:
I have a web service that logs into a database and retrieves information. Everything works fine if the login is successful. However if the login is unsuccessful, I can't get the web service to...
0
by: Jean | last post by:
Hi, I have a question about logins and sql server express and an ASP.NET aplication. I put this question in sql server newsgroup, but without real answer sofar. I created a login 'Network...
2
by: Homer | last post by:
Hi, I have an ASP.NET 2.0 Intranet app that works fine on a test server running on Win2003 Server with IIS 6.0. However, it fails when I port it over to the production server running on the...
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.