PDA

View Full Version : [c#] Database connection


MRMAN
06-28-2006, 11:49 AM
Hello.

I have made two projects. The first is a windows application and the second is a ASP.NET Web Application.

The windows app is stored in c:\winapps\staffing\
and the web app is stored in c:\Inetpub\wwwroot\staffing

The applications should do the same thing. Bacisally when i user enters a id number in box one or the name in box two the details will be taken from the database and fill in the missing text.
i.e. the user enters 1 and the name of person 1 will be filled in the other box.
This works well in the windows app. So well infact i decided to make the code work in a web app.

But i have gotten a problem. when i try and access the database it says

"Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.
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 '(null)'. Reason: Not associated with a trusted SQL Server connection.
Line 60: SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connectionString);
Line 61: DataSet myDataSet = new DataSet();
Line 62: dataAdapter.Fill(myDataSet);
Line 63: DataTable table = myDataSet.Tables[0];
Line 64: int numberRows = table.Rows.Count;

Source File: c:\inetpub\wwwroot\staffing\webform1.aspx.cs Line: 62 "

Does anyone know if this is caused by being on the localhost iis (forgot to say that). The c:\inetpub\wwwroot\staffing\webform1.aspx file can be access http://localhost/staffing/webform1.aspx".

Thank You

Brandoe85
06-29-2006, 10:03 PM
Make sure both windows and sql authenication are enabled in enterprise manager. With asp.net you'll be connecting through the ASPNET account, therefore you'll need to make sure that user has the appropriate privleges.

MRMAN
06-30-2006, 11:41 AM
I feel a little stupid.
Thank you its sorted now.
ll i needed to do was set the permission for the ASPNET user on the tables.

Brandoe85
06-30-2006, 03:01 PM
Good, the main thing is you understand that it's not the same as connecting through a windows application. Most of the database errors like that will mostly be relating to the ASPNET user account's permissions.

Good luck :)