Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error connecting to SQL databse

Status
Not open for further replies.

iainmc

Programmer
Dec 2, 2002
53
GB
When i run my first web page, on the line of code where i open a connection to my db (so i can run a stored proc) i recieve this error message in my explorer window....

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

I have no idea how to resolve this error, any help would be great.
 
This has been addressed here:

thread855-530618

That article is referring to using Windows authentication. What kind of authentication are you using for your web site?
 
Are you using Windows Integrated Security (passing to SQL Server the username/password that you are logged on with) or SQL Server authentication (a hard coded id/password in your connect string)?

Assuming that you do have the proper permissions to log onto the SQL Server DB and that you're using Windows Integrated Security, you will have to add the following entry to your web.config file:

<system.web>
<identity impersonate=&quot;true&quot; />
</system>

This is because your .aspx page is running under the ASPNET account and the ASPNET account doesn't (and shouldn't) have permission to log onto the SQL Server. Including the above line will have the ASPNET account &quot;impersonate&quot; your logged on credentials.

Assuming that there are no other problems (and there can be many others), this should work.
 
Thanks for that, it appears to have fixed that problem but now it seems to be looking for a User called &quot;\&quot; for some reason.

The error is now......

Login failed for user '\'.

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 '\'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SqlException: Login failed for user '\'.]
System.Data.SqlClient.SqlConnection.Open()
AII_Web.WebForm1.Page_Load(Object sender, EventArgs e) in C:\WINNT\Profiles\mcin0024\VSWebCache\wyton_aiiwebsvr\inetpubs\ System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +29
System.Web.UI.Page.ProcessRequestMain() +724


Any ideas? I'm pretty sure my user name is not &quot;\&quot;
 
Just guessing, but...something may be wrong with your username.

What is the name of the account you're logged on with? Is it in the format of domain\username? You can verify your credentials by including the following in your page or code-behind:

string UserName = User.Identity.Name;
Label2.Text = &quot;You are logged on as: &quot; + UserName;
 
Yeah, my user name is in the format of domain\username.

I did think this may have something to do with it but was not sure.
Know of anyway around this prob, i've been stumped for ages now, starting to pull the hair out me head!!!


 
Here's some very general possibilities:

Did you try putting the above code I mentioned in your page?

Does it return a valid username?

Does this username have the proper permissions to log onto the database?

What about trying another username?

Have you ever successfully connected to a SQL Server database via an .aspx page? If so, has anything changed?
 
This is my first atempt at connecting to SQL server through ASP.Net so i have nothing to compare with unfortunately, i am also sure that my login works on the database.

BUT... when i typed your code on the load of the form, the variable i set to hold the username is empty (&quot;&quot;).
Does this mean it is not picking up my NT login?
 
in addtion to have the <identity impersonate=&quot;true&quot; /> your web.config file must also have the follow tags set between the system tags:
Code:
<configuration>
  <system.web>
    <authentication mode=&quot;Windows&quot; /> 'user windows login
    <identity impersonate=&quot;true&quot; />   'impersonate the user
    <authorization>
      <deny users=&quot;?&quot; />              'deny unknown users
    </authorization>
  </system.web>
</configuration>
There are other tags between the system.web tags, but these are the onese that allow windows authentication. By default the tag between authoriztion tags is <allow users=&quot;*&quot; />.


Jason Meckley
Database Analyst
WITF
 
I already have the extra lines in my web config file so i changed the allow users to your deny users code but i still receive the error.
I am confident that my login does work with Windows itegrated secutity on the SQL server as i've been using it for about 2yrs now.
I am starting to think there is a problem on the server (Sql server) end - could this be possible and any idea what it could be.

Thanks

Iain Mc
 
I'm not 100% sure of this but I think you also need to disable anonymous access in IIS and use NT Challenge/Response for it to actually pick up your NT login.

--James
 
I have unchecked the annonymous user account in IIS but can't see anything called NT Challenge/Response, where do i set this?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top