You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

<UPDATE Date=November 26, 2007>

I find that a lot of people have been finding this article a little useful and at the same time finding it hard to get to the second part of the article.  So here below is the link for the Part II of this article. 

http://geekswithblogs.net/ranganh/archive/2005/05/25/40503.aspx

</UPDATE>

Integrated authentication allows for SQL Server to leverage Windows NT authentication to validate SQL Server logon accounts. This allows the user to bypass the standard SQL Server logon process. With this approach, a network user can access a SQL Server database without supplying a separate logon identification or password because SQL Server obtains the user and password information from the Windows NT network security process.

Choosing integrated authentication for ASP.NET applications is a good choice because no credentials are ever stored within your connection string for your application.

However, you may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" while trying to use Integrated Windows Authentication and your application needs to access the SQL Server Database using Trusted Connection.

Lets examine two scenarios where this error can occur.

1. Your IIS (Webserver) and SQL Server are on the same machine.

The first thing to check is that whether the SQL Server is configured to use Mixed Mode Authentication or Integrated Authentication.

To do that, do the following steps :-

1. Click Start - Programs - Microsoft SQL Server - Enterprise Manager to open the Enterprise Manager.

2. Connect to the appropriate Server if the SQL is a client installation.

3. Right click on the Server Node and click on Properties.

4. This opens the Properties Dialog.

5. Switch to the Security Tab.

6. Under the Security section, make sure the Option SQL Server and Windows is selected.

7. This ensures that your SQL Server is running under Mixed Mode Authentication.

The Next step is to ensure that the ASPNET account (IIS_WPG in case of Windows server 2003) has the appropriate access to the Database.

To do that, do the following steps:

1. Open SQL Server Enterprise Manager (Start - Programs - Microsoft SQL Server - Enterprise Manager), select the appropriate server, and expand the Security folder.

2. In the Logins check whether the IIS_WPG is listed.

3. If it is not listed, right-click on Logins and select New Login

4. In the Name: textbox either enter [Server/Domain Name]\IIS_WPG or click on the ellipses button to open the Windows NT user/group picker.

5. Select the current machine’s IIS_WPG group and click Add and OK to close the picker.

6. You then need to also set the default database and the permissions to access the database. To set the default database choose from the drop down list,

7. Next, click on the Database Access tab and specify the permissions.

8. Click on the Permit checkbox for every database that you wish to allow access to. You will also need to select database roles, checking db_owner will ensure your login has all necessary permissions to manage and use the selected database.

9. Click OK to exit the property dialog.

Your ASP.NET application is now configured to support integrated SQL Server authentication.

I will explain the next scenario of Webserver and SQL Server residing in different machines, in my
next article.

Read
Part II

Cheers and Happy Programming.

posted @ Wednesday, May 25, 2005 8:12 AM

Print

Comments on this entry:

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Irma at 6/7/2005 10:37 PM
Gravatar
Thanks a lot for the article!!!
It works wonderfully!

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by drew at 6/27/2005 7:14 PM
Gravatar
Could you email me when part 2 is out?
sqlerr.1.zdux0012[at]xoxy.net

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by part 1 at 7/6/2005 10:07 PM
Gravatar
You're awesome! I've been looking everywhere for a solution... yours was the only helpful one! thank you sooo much!

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by msummerlin@wabtec.com at 7/14/2005 2:43 PM
Gravatar
Please email part 2 when it is out.

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Ajay Sharma at 7/25/2005 8:34 AM
Gravatar
When the application is on the same computer as an instance of SQL Server 2000 then okay this is working fine but When the application is on a separate client, a network IPC, such as TCP/IP or Named Pipes, is used to communicate with SQL Server. then i have geting problem.
Please give me solution.


# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Joe Lima at 8/2/2005 8:29 PM
Gravatar
can you e-mail me part2. That's the situation here at work.

joe.lima@starz.com

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Mark Robinson at 8/5/2005 5:53 PM
Gravatar
Thank you, I searched the web for quite a while, your blog was the only one that explained it properly. Thanks

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by LN at 8/5/2005 11:11 PM
Gravatar
Did anyone ever get part 2????

Thanks.

lnn714@hotmail.com

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Faisal at 8/16/2005 8:33 AM
Gravatar
Would really appreciate if you could expand this to include the second scenario: WebServer and SQL Server are on separate machines.

Many Thanks

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Selami Ozlu at 8/19/2005 6:41 PM
Gravatar
Hi, could someone email me 2. part, please.

selamiozlu@hotmail.com
sozlu@banktrade.com
Thank you

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Mike at 9/6/2005 12:33 PM
Gravatar
Has anyone received part 2 yet? If so can you please email it to me?
MTyszkiewicz@american-community.com

thanks

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by pinoydip at 9/7/2005 1:58 PM
Gravatar
we are also experiencing th same issue can someon email me the 2nd part of this @ oa90@hotmail.com .... thanks a lot

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Melanie at 9/28/2005 11:34 AM
Gravatar
Hi,
Can someone send me the part 2 ?
Or does anyone fix the problem when Web Server and SQL Server are on 2 different machine ?

thanks
melune23@msn.com

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Hopeisontheway at 10/3/2005 4:23 PM
Gravatar
where is part Two ?

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by R.Tutus at 10/4/2005 8:35 PM
Gravatar
Hi I am using WINDOWS XP but I always get the same error: Login failed for user even with doing all the changes you suggested in this article.
The error is Login failed for user 'Administrator'.]

This is the connection string I am using in ASP.NET (visual studio 2003):

Dim cn1 As New SqlConnection("Workstation ID=TUTUS;Data Source=TUTUS;Initial Catalog=atworkwebportal; user ID=Administrator")

where Tutus is my computer, and arworkportal is the database.

I d appreciate your help guys.

# Integrated authentication SQL Server to leverage Windows NT authentication

Left by SQL Server at 10/28/2005 9:02 AM
Gravatar
&nbsp;
Part I:
http://geekswithblogs.net/ranganh/archive/2005/05/25/40489.aspx
Part II:
http://harishmvp.blogspot.com/2005/05/you-may-receive-error-login-failed-for_25.htm...

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by balamurugan at 11/24/2005 2:00 PM
Gravatar
The error occurs only in asp.net with c# but in asp using macromedia it's working fine.

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Skanda Subramanian; Sunil Kumar at 12/10/2005 12:43 AM
Gravatar
In the browser try enabling Integrated Authentication. You may also wish to check your Kerberos setup - NTLM is expected to fail in a dblhop.

Skanda & Sunil

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Jonatan Rullman at 12/25/2005 8:49 PM
Gravatar
This is unbelievable. I've been trying to get this to work for i dont know how long. I always resort to sql authentication instead. All the other guides talk about adding the asnet-account and never mentiones iis_wpg. This worked as a charm first try. Thanks a million.

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by iris at 1/6/2006 6:17 AM
Gravatar
Sorry, i face problem at part 2. I don't know how to "Create a Domain Account with priveleges similar to ASPNET or NETWORKSERVICE.". Can someone help me?

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by L at 1/18/2006 12:04 PM
Gravatar
did not work for me.. still get same error.. can sum1 give me a conn string they used.. my sql has a password.. thjs

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Soumendra at 2/23/2006 2:47 AM
Gravatar
It did not work for me as I have a 2tier arch and the server is protected by firewall.
I tried using impersonating the logged in user with the account the firewall accepts but I get same frustrating error ... Please help me.

# SQL SERVER error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection"

Left by Sanjay Chauhan at 2/27/2006 4:22 AM
Gravatar
Connection failed:
SQLState: '28000'
SQL Server Error: 18452
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '(null)'.. Reason: Not associated with a trusted SQL Server connection.

Note: This Error comes only in a single PC rest three PC Working properly

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Timorthy at 3/5/2006 2:20 PM
Gravatar

I'm using SQL Server 2005 Express Edition, C# and Visual Web Developer and facing the same problem. Can anyone help me figure out in SQL Server 2005 Express Edition?

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Timorthy at 3/5/2006 2:26 PM
Gravatar

One more thing concerning is that I run those tools in the same computer. In SQL Server 2005 Express Editon, you can choose Either:

From the internet: Select this option if users will access your web site from the public internet. Users will be required to log on using a web form. The site will use forms authentication to identify users according to user information that you store in a database.

Or:

From a local network: Select this option if users will access your web site only from a private local network. The site will use built-in Microsoft Windows authentication to identify users. Users with a valid Windows user name and password will be able to access your site.

In the sql server, you cannot choose "Mixed Mode Authentication or Integrated Authentication".

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Pete at 3/21/2006 8:52 AM
Gravatar
Could anyone send me the Part II?

Thank you in advance.

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by rakesh at 3/30/2006 10:42 AM
Gravatar
I am using XP Pro, IIS 5, MSDE (SQL Server) in which you dont have much facility to create or change options etc... so cant give access to ASP account... what should I do??
Both MSDE & IIS are on same machine...
Please help...

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Jim at 3/30/2006 4:45 PM
Gravatar
I get this error using a 3rd Party MS Access application. When I run from my machine, I am fine (I have admin rights on the SQL Server). When I run from a user's machine as the user, the access Application fails and gives me the Login '(null)' error this thread talks about.

Any solutions for MS Access??

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by gudiya at 4/20/2006 11:53 AM
Gravatar
Thanks a lot.It was really helpful...
How can I check ur messages continously or a forum where I can add myself and ask my other problems

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Munira at 5/17/2006 12:06 PM
Gravatar
This is just brilliant!!! Thank you so very much! I have really been at this forever!!! I had done bits and peices of it... but this article just puts it all together and tells you what you are missing!
Cheers!

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Khaaj at 6/21/2006 9:28 PM
Gravatar
can someone send me the Part 2 i.e. scenario of Webserver and SQL Server residing on different machines. My email address: khawaja_hammad@acl.com.au
Thankx in advance.

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by gajee at 7/7/2006 6:55 AM
Gravatar
I hope this works, I am gonna try it out and then reply here........i have wracked my head over the past 2 days...........fingers crossed IT SHOULD WORK

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by cayrol at 7/12/2006 2:28 AM
Gravatar
i'm interested this web actually they are solution as a quide in sql and dot.net problem... can someone give me idea to solve this problem..i already try part 1 but it still have a same problem...please help me...

email : kazwanm@modenas.com.my

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by iliev at 7/18/2006 8:30 AM
Gravatar
in sql server 2005 epxress dosn't have security tab :(
please help me !!!!

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Mikey at 8/15/2006 6:44 PM
Gravatar
Works for me; thank you!

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Byock at 8/23/2006 10:04 AM
Gravatar
Thank you very much...

This article is very informative...and useful...

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Rebecca Weathersby at 9/7/2006 8:33 PM
Gravatar
Incredibly helpful...

I have been experiencing the error message in the title infrequently but regularly in a web application I developed for a customer. I had no idea how to fix it, as the connection worked most of the time, and even when the user got the error, if they retried the action it would work.

The only other information I could find online other than using mixed authentication in SQL 2000 was using named pipes... my application is using a production database however, and I did not want to go jacking around with that, or have to reconfigure everyone's ODBC data connections!

I had pretty much given up on this problem that has been bothering the customer for weeks/months now...

The IIS_WPG group was the key! They are using windows 2003 server, which I have little experience with and could not test in the office before deployment.

Your detailed, step-by-step instructions saved my application :) It has been two days now without any "Login failed for user '(null)'" errors, whereas they were previously experiencing 2-3 per day.

Thank you so much for posting this walkthrough!!!

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by manimegalai.s at 9/14/2006 3:45 AM
Gravatar
thank u
i am getting an error( keyword not supported provider)

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Mohammed Jawish at 10/29/2006 11:38 AM
Gravatar
yes you should replace the name by the IP address but make sure when u go To IIS and create new web site to assign an IP Address
jawishm@yahoo.fr

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Alex Steward at 12/6/2006 9:09 AM
Gravatar
Hi,
I am also getting the same error in MSDE.But using osql.exe I am able to login as 'sa' into the server.

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Hannele at 12/7/2006 2:32 PM
Gravatar
Thank you for your help!

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by ray at 12/7/2006 4:52 PM
Gravatar
could someone email me part 2 please? My email id: pnn07@hotmail.com

Thank you.

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Mahen at 12/28/2006 6:13 AM
Gravatar
I am using SQL Server 2005 and I have done what was explained here but still I am getting this error. Can anyone help me. My email id is joshimahen@gmail.com.
Please send soultions in mail only

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Kaviraju at 3/14/2007 1:56 PM
Gravatar
Its all about database connection string. I mean, connection should not be windows autheticated type, rather it should be with user name and password. This property has to be set in IIS also.

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Todd Kandaris at 3/14/2007 11:50 PM
Gravatar
UGH!! I wasted a whole day on this problem. The solution was quite simple once I realized that the problem was not with my sql server permissions, but with the local IIS server settings on my .Net development machine.

I had a suspicion that this might have to do with how IIS was attempting to connect to the sql server in question, but I didn’t have a clue as to where to go to change how it was submitting the login credentials.

The answer was in the IIS manager by selecting the properties of the website in question (I used the Default Web Site), then selecting the ASP.NET tab in the website properties dialog.

There are two buttons on the bottom of the tab screen one for global one for that particular web site node.

I chose global, because I don’t want to do this more than once. At this point another dialog will pop up (ASP.NET Configuration Settings) with 7 tabs.

Choose the “Application” tab. At the bottom of that tab screen there is a group called Identity settings. Make sure the Local impersonation checkbox is checked.

Don’t put anything in the User name and Password if you want it to use your PC login credentials.

Click OK all the way back and restart IIS. You should be golden.

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Need Help at 3/15/2007 11:18 PM
Gravatar
Maybe I'm just not getting it... I get the same message as everyone else in this chat, which is rather frusterating. I've had to create an non-Windows NT account on my SQL Server DB in order to access anything. Here's my scenario.

My db is on my db server which is set up for Windows NT. All Windows NT log in accounts besides mine seem to work just fine. Mine gives me the above error message. I have IIS installed on my machine because I am using SQL 2K5 management studio, even though my db is 2K. All my other users that aren't having problems also have IIS installed.

Since my computer is not the db server, but is running IIS I can't do what you've outlined above.

Help please!!!

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by Roger Crockett at 3/19/2007 3:31 PM
Gravatar
Todd Kandaris - Your reply ROCKED! I've been banging my head with these user permissions for days!!! I have My DB and Website on seperate networked servers and this worked just like it is suppose to!! --Thanks!!!

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Part I

Left by MAS at 3/23/2007 10:37 PM
Gravatar
thank youuuu soooo muchhhh! i have this problem for a few days and i was confuse,
but only your blog help me.thankssssss.have a good time.

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Pa

Left by Art Z. at 6/19/2007 11:27 AM
Gravatar
-->IF YOU ARE USING WINDOWS 2003 SERVER!!!!!<--

You must enable DTC access. By default it is not installed on Windows 2003 Server (all flavors).

Step One: Steps to Enable Network DTC Access (Run on all machines requiring DTC access)
1. Click Start, point to Control Panel, and then click Add or Remove Programs.
2. Click Add/Remove Windows Components.
3. Select Application Server, and then click Details.
4. Select Enable network DTC access, and then click OK.
5. Click Next.
6. Click Finish.
7. Stop and then restart the Distributed Transaction Coordinator service.
8. Stop and then restart any resource manager services that participates in the distributed transaction (such as Microsoft SQL Server or Microsoft Message Queue Server).

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Pa

Left by Ivan Delerdivan at 9/5/2007 5:56 AM
Gravatar
Hi,
i had the Windows XP Embedded without Service packs up and running and today I've updated my XP Embedded Environment first to SP1 and than to SP2. The sevice packs have also updated the database and the databade engine. XP Embedded installs a MS SQL Database (I assume it is the version 2000) but there is no Database Manager installed. First I found that no communication methods are enabled. I started the "SQL Server Utility" and activated the methods TCP/IP and "Named Pipes" after this change were my applications (Target Designer, Component Designer and Component Database Manager) able to start becouse they can connct to the database. But I had backed up my old database which includes a lot of self defined devices and now I want to restore my old database but I'am not able to connect to the database via a the database manager "DbaMGR2k" I tried as "sa" or "install" user to login an I get always the error message "Not associated with a trusted SQL Server". I also tried to login via "osql" with same result.
I inserted also in registry
HKLM\Software\Microsoft\Microsoft SQL Server\Instance Name\MSSQLServer\LoginMode
a DWORD with value 0 according to hint on page "http://support.microsoft.com/default.aspx?scid=kb;en-us;285097"
But it does not solve my login problem.

Can some one help me?

Thanks in advance
Ivan

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Pa

Left by Nil at 1/19/2008 1:06 AM
Gravatar
Thanks a lot!!! the article was really really helped me out. Great explanation

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Pa

Left by A.s at 4/9/2008 5:51 AM
Gravatar
That helped a lot , thanks

www.CodeExplore.com

Make money writing articles

# re: You may receive the error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection" - Pa

Left by Deepesh at 4/25/2008 4:40 PM
Gravatar
Thanks Dude u solved one of my big problems

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345