?
Solved

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

Posted on 2002-07-15
15
Medium Priority
?
5,328 Views
Last Modified: 2009-07-29
When I am using NT Security to conect to a sqlserver database from a vb.net form using asp I get the following error:

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

How do I fix this?



 
0
Comment
Question by:kenmck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
15 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 7154080
Could you show your connectionstring?

All you need are some additional items.

CJ
0
 

Author Comment

by:kenmck
ID: 7154132
   <sessionState
            mode="InProc"
            stateConnectionString="tcpip=127.0.0.1:42424"
            sqlConnectionString="data source=127.0.0.1;user id=sa;password=lob"
            cookieless="false"
            timeout="20"
    />


Thanks,
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7154184
I do not suggest using the sa user for it. And you have not specified a database.

Change it to the following:

"data source=localhost;integrated security=sspi;database=yourdatabase"

Now the user account that is being used to access the database is the ASPNET user (remember you are using WinNT security).

So you will need to give that user access to the database within SQL Server.

You know how to do that?

CJ
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 22

Expert Comment

by:CJ_S
ID: 7154185
Oh also:

"data source=localhost;integrated security=sspi;database=yourdatabase;Trusted_Connection=yes"

0
 

Author Comment

by:kenmck
ID: 7154351
I have set up my connection string to the following:

Dim strConn As String = "server=bkrenf;database=discovery;uid=sa;pwd=lob"

and I get connected.

When I use

Dim strConn As String = "server=bkrenf;integrated security=sspi;database=discovery;Trusted_Connection=yes"

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

Any idea why?
0
 

Author Comment

by:kenmck
ID: 7154393
I have set up my connection string to the following:

Dim strConn As String = "server=bkrenf;database=discovery;uid=sa;pwd=lob"

and I get connected.

When I use

Dim strConn As String = "server=bkrenf;integrated security=sspi;database=discovery;Trusted_Connection=yes"

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

Any idea why?
0
 

Author Comment

by:kenmck
ID: 7154406
I have set up my connection string to the following:

Dim strConn As String = "server=bkrenf;database=discovery;uid=sa;pwd=lob"

and I get connected.

When I use

Dim strConn As String = "server=bkrenf;integrated security=sspi;database=discovery;Trusted_Connection=yes"

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

Any idea why?
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7154409
I think because of the integrated security item.

The first error is because you have not provided a default database you want to connect to. I'd still say that the Trusted_Connection property should be in there since it is a trusted connection. And if it is you will encounter an error when you ommit that item.

I have no idea why your first sample works without the Trusted_Connection item. :-/

CJ
0
 

Author Comment

by:kenmck
ID: 7154549
Nope still cannot get this to work. How do I use a Trusted Connection or NT Security to connect?

Have you got any examples?
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7154610
I used the following:

Provider=sqloledb;initial catalog=MYDATABASE;Trusted_Connection=yes;data source=(local);Connect Timeout=20


However, searching for the error you got you get to some pages that explain this error in more detail:

"Trusted_Connection=true;database=MYDATABASE;server=(local)"
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 7155822
Try setting the impersonation to true in web.config file. By setting it to true, you will be connecting to SQL server under the context of windows login that is logged oonto clinet machine. Otherwise you are connecting as ASPNET account.

<identity impersonate="true">
0
 

Author Comment

by:kenmck
ID: 7156517
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'

is now my error message.

Help!
0
 

Author Comment

by:kenmck
ID: 7156543
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'

is now my error message.

Help!
0
 
LVL 4

Accepted Solution

by:
kpkp earned 400 total points
ID: 7156807
What type of connection do you _want_ to use?  If you want to specify and account to use in the connecition string, then (assuming this is a SQLServer) use:

Dim strConn As String = "data source=bkrenf;initial catalog=discovery;user id=sa;password=lob"


are you assigning the connecion string to the SqlConnection object?
0
 

Expert Comment

by:kaytrim
ID: 7190846
Sorry to barge in on the experts here but here is a sample connection string that I use to asscess from ASP.NET

"server=servername; trusted_connection=false; uid=username; pwd=password; Database=databasename"

The key is that the trusted connection can only be true of the sql server and the app server are the same machine.

Micahel
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question