PDA

View Full Version : Can't figure out this error!


chelvis
06-16-2006, 03:40 PM
I am doing this in Visual studio 2003 and SQL Server 2000.

I created a web form with a DataGrid and then connected to a database called 'Contacts'. The database has a table called Contacts. I created a connection to the database (sqlConnection1) and a data adapter (sqlDataAdapter1) and set a DataSet (dataSet11). Follwoing is the code:


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Chapt05
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Web.UI.WebControls.DataGrid dataGrid1;
protected Chapt05.DataSet1 dataSet11;

private void Page_Load(object sender, System.EventArgs e)
{
// Fill the data set.
sqlDataAdapter1.Fill(DataSet1);
// Update the DataGrid.
dataGrid1.DataBind();

}
}
}



When I compile I am getting the following error:
'Chapt05.DataSet1' denotes a 'class' where a 'variable' was expected.

Why is this error? I didnt do anything different and I am not being able to figure this out - am new to this and learning it.

rlemon
06-16-2006, 04:23 PM
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Chapt05
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Web.UI.WebControls.DataGrid dataGrid1;
protected Chapt05.DataSet1 dataSet11;

private void Page_Load(object sender, System.EventArgs e)
{
// Fill the data set.
sqlDataAdapter1.Fill(dataSet11);
// Update the DataGrid.
dataGrid1.DataBind();

}
}
}

chelvis
06-16-2006, 07:34 PM
Yes, I tried that too. When I do that, it compiles fine. But when I run it, I get the following error in my IE browser and line 33 is in red color:

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

Source Error:

Line 31: {
Line 32: // Fill the data set.
Line 33: sqlDataAdapter1.Fill(dataSet11);
Line 34: // Update the DataGrid.
Line 35: dataGrid1.DataBind();


Source File: c:\inetpub\wwwroot\chapt05\webform1.aspx.cs Line: 33

otaku149
06-16-2006, 09:32 PM
You must have the default trusted connection account within the user list with db_owner rights to the database:


Open SQL Server Enterprise Manager
Expand CHELVI\NETSDK
Expand Databases
Expand the database (the one you try to connect)
Right-click on Users + New database user...
Use the drop-down list to select the Login name: CHELVI\ASPNET
Tick public and db_owner
Click OK


To connect to the database:
server=CHELVI\NetSDK;database=YourDatabaseName;Trusted_Connection=yes

Brandoe85
06-16-2006, 09:54 PM
In the future, please use a more descriptive subject when posting a question. See posting guidelines. (http://www.codingforums.com/postguide.htm)