Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Trusted user vs database user

I have been working on a small project using VS.Net.
Programming platform Windows XP connected to a domain.
Web Server and SQL Server are separate machines

I connect to SQL server using the followin code :

SqlConnection myConnection = new
SqlConnection("server=ServerSQL;uid=sa;pwd=sa;database=proj1");

Everything is working fine, but I would like to try Trusted connection
insterad of database user.

When I try,

SqlConnection myConnection = new
SqlConnection("server=ServerSQL;Trusted_Connection=Yes;database=proj1");

I get the following error:
Login failed for user '(null)'. Reason: Not associated with a trusted SQL
Server connection

I think it has something to do with the user name of IIS when it tries to
connect to SQL Server.
So, on the webserver I tried to change the logon user for IIS Admin and WWW
to a domain user with all the rights, but then I get a nasty error telling
me aspnet_state.exe can't start.

any idea?

Thanks
Youri
[1085 byte] By [Youri Fedov] at [2007-11-9 21:10:07]
# 1 Re: Trusted user vs database user
First, this is SQL discussion not SQL Server. :)

To attempt to answer your question. If I remember rightly, you need an additional
parameter (integrated security=sspi I think). It has been a few years so
I don't know. I usually cheat and allow VB/.Net to build me a connection
string and then copy it. It could be that trusted connections don't work
on separate machines (http://216.239.39.100/search?q=cache:DKSn1cJ3oD8C:www.experts-exchange.com/dot_net/Q_20323421.html+Login+failed+for+user+%27(null)%27.+Reason:+Not+associated+with+a+trusted+ SQL&hl=en&ie=UTF-8).

Also make sure the user the app is running under has been added to the database.
Your best bet is to run under COM+ and set the security there. Messing
with IIS security isn't worth it.

Lastly, I would suggest you continue using SQL Server Security and not Windows
Security. This is the way I do it so I don't have this problem.

"Youri Fedov" <youriREMOVEfedov@yahoo.com> wrote:
>I have been working on a small project using VS.Net.
>Programming platform Windows XP connected to a domain.
>Web Server and SQL Server are separate machines
>
>I connect to SQL server using the followin code :
>
>SqlConnection myConnection = new
>SqlConnection("server=ServerSQL;uid=sa;pwd=sa;database=proj1");
>
>Everything is working fine, but I would like to try Trusted connection
>insterad of database user.
>
>When I try,
>
>SqlConnection myConnection = new
>SqlConnection("server=ServerSQL;Trusted_Connection=Yes;database=proj1");
>
>I get the following error:
>Login failed for user '(null)'. Reason: Not associated with a trusted SQL
>Server connection
>
>I think it has something to do with the user name of IIS when it tries to
>connect to SQL Server.
>So, on the webserver I tried to change the logon user for IIS Admin and
WWW
>to a domain user with all the rights, but then I get a nasty error telling
>me aspnet_state.exe can't start.
>
>any idea?
>
>Thanks
>Youri
>
>
MarkN at 2007-11-11 23:52:58 >