database connection errors

andycharger

Well-known member
Joined
Apr 2, 2003
Messages
152
Hi.

Im trying to connect to my SQL SERVER database and im having some troubles.

I get the following message when I press a button on an ASP form to connect.


Server Error in /inet1 Application.
--------------------------------------------------------------------------------

Login failed for user ADMINIT1\ASPNET.
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 ADMINIT1\ASPNET.

Source Error:


Line 51: Dim cnSQL As New SqlConnection()
Line 52: cnSQL.ConnectionString = strSql
Line 53: cnSQL.Open()
Line 54:
Line 55: End Sub


Source File: c:\inetpub\wwwroot\inet1\logon.aspx.vb Line: 53

Stack Trace:


[SqlException: Login failed for user ADMINIT1\ASPNET.]
System.Data.SqlClient.SqlConnection.Open()
inet1.logon.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\inet1\logon.aspx.vb:53
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()


So there seems to be a problem with my access to the database. I thought i had al lof the permissions set. Can anyone shed any lights as to what it may be.
 
Although you as a user may have permissions to the database, by default ASP.Net applications will attempt to connect as the account ASPNET. You either need to give this user permissions to the database or look at getting the WebApp to impersonate the calling user.
 
A genius you are!

that user, ASPNET, I dont know where it has come from. Can you tell me how I find it and give it permissions?

Do all applications built in .NET use this login access?(ASPNET)

Any help would be appreciated.
 
All ASP.Net applications execute as the user ASPNET, it is created as part of the framework installation.

You can give it permisions to the database through SQL Enterprise manager
 
This is one of the most popular problems Ive ever read in newsgroups. I wonder if anyone knows if theres a KB article (or any other link for that matter) that enumerates a step-by-step troubleshooting guide for this problem.
 
Its not really troubleshooting, its just knowing the basics of SQL Server administration. If youre a normal developer, you setup SQL Server on your own box and you log in as "sa" with no password. Thats the default user/pass during setup (though you have to bypass a warning about the sa password being blank).

The problem you might be having is if your SQL Server install is only allowing SQL Server userid/password to log in. I dont have SQL Server on this machine (I can look in the morning), but youll want to check the server settings/options. Look for something about mixed security. You WANT mixed security. It means SQL Server logins can either be username/password created ONLY in SQL Server (managed through enterprise manager) or an NT/Win2000 userid/password (your domain account).

If your SQL Server only allows SQL Server uid/pwd to login (which is how the sa account is created), youll need to change it.

Once youre sure SQL Server allows mixed authentication, youll want to make sure the ASPNET user (just like your username) has permissions to the Server and database. In enterprise manager, go to the Logins (or is it Security) node in the tree. See what accounts show up. If you dont see:
ADMINIT1\ASPNET
then youll have to add. Right click on the tree and select Add new user then make sure its set for Windows Authentication and choose the user (or paste in the name). Now assign that user some level of permissions to certain databases (or however you want your security to work).

I believe the .NET documentation is limited in its descriptions of setting up the ASPNET user account to have permissions to a database since its not really a .NET thing, but a SQL Server permissions issue.

Keep in mind that the ASPNET account is JUST a regular windows account like your username or your bosss. It just gets created automatically so you can keep track of what permissions your website has (including access to your database).

-Nerseus
 
Back
Top