Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-27
15
Medium Priority
?
1,812 Views
Last Modified: 2008-02-07
I wrote a SQL connection program. It works in connecting to the SQL server in the console application program. But when I copied the same code to a web form under button_click event handling, system reported:
"Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection"

Why it works in C# console application while not working in the asp.net web form? They use the same SqlConnection:
new SqlConnection("Initial Catalog=DataMasters; Data Source=Abcdefg ;Integrated Security=SSPI");

And the security has been set up as: Authentication: SQL Server and Winows.
On the startup service account (start and run sql server in the following account) (in security configuration), system administrator selected an account name and a password already though (instead of using system account).

thanks a million,
Scott
0
Comment
Question by:heyday2004
[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 17

Expert Comment

by:AerosSaga
ID: 12424813
do you have Identity Ipersonate=true in your web.config?

Aeros
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12424818
<identity impersonate="true" />
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12424823
what account is it running under in IIS?  
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:AerosSaga
ID: 12424850
That is the account that will need to have a sql server account to access the db
0
 
LVL 8

Expert Comment

by:boulder_bum
ID: 12424885
Is there an ASPNET account set up for the database?

You may either need to set up an account, or configure credentials to be sent properly accross the network (I believe the ASP.NET worker process only has anonymous access to network resources by default).

http://support.microsoft.com/default.aspx?scid=kb;en-us;307002
0
 
LVL 9

Expert Comment

by:riyasjef
ID: 12424891
try this

new SqlConnection("Initial Catalog=DataMasters;uid=sa;pwd=; Data Source=Abcdefg ;Integrated Security=SSPI");

RJ
0
 

Author Comment

by:heyday2004
ID: 12425070
Thanks. Here are some parts that I have doubt with in my web.config:
<authentication mode="Windows" />
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20" />
...

When I added <identity impersonate="true" />, there was another error:
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.

Also, how to check what account is running under IIS?

Thanks.
0
 
LVL 17

Accepted Solution

by:
AerosSaga earned 1500 total points
ID: 12425089
ok you need to create an Active Directory Windows account for the application to run under or use an existing one.
Go to your IIS manager and click on the site properites and then look under the directory security tab.  There it wil let you choose
the account the application runs under set it to your desired account with the sql server account and all will be well.

Aeros
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12425091
don't worry about that top stuff its fine.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12425135
currently its running with anonymous access as the default process.  That is why the username is null, and you are being denied.
0
 
LVL 25

Assisted Solution

by:nauman_ahmed
nauman_ahmed earned 300 total points
ID: 12425506
1. Create a SQL Server user using SQL Server Enterprise Manager. Make sure that your SQL server supports both the Windows and SQL Authentication.

2. Use the follwoing connection string:

Data Source=192.168.0.10,1433;Network Library=DBMSSOCN;Initial Catalog=northwind;User ID=SQL_USER;Password=SQL_PASSWORD;"

In your console application, you didnt have any problem as the application was accessing the SQL server under the privileges of user account that you are logged in. However, in asp.net web application, ASPNET user account do not have high privileges and if you do not provide the user account info in the connection string, it tries to access the server using ASPNET account that by default do not have permission to access the server.

HTH, Nauman.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12426216
0
 
LVL 28

Assisted Solution

by:mmarinov
mmarinov earned 200 total points
ID: 12426577
Hi heyday2004,

the connection is open under the account it is executable. when you create a web site the defaul settings are - enabled for the anonimous user
when you use Windows Authentication you can not retrieve ( .net also :) ) which is the current user that is logged into the machine
so when you try to connect to the SQL Server .net pass (null ) user

to remove that you have to remove anonymus access for your web site
1. Open Internet Information Service console
2. RIght click on your virtual directory/web site
3. go to Directory Security Tab
4. Click on Edit button in the  Authentication and access control
5. uncheck the checkbox Enable Anonymous Access

Regards!
B..M
0
 

Author Comment

by:heyday2004
ID: 12427815
Thanks  a lot, all! I created a account and solved the problem. Thanks again.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

609 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