Monday, March 19, 2012

Error on DataAdapter.fill

i have this code :

if(! IsPostBack)
{
string strConnection = "server=localhost; uid=sa;pwd=sasasa; database=northwind";
string strCommand = "Select * from Customers";

SqlDataAdapter dataAdapter = newSqlDataAdapter(strCommand, strConnection);

DataSet dataset = new DataSet();

dataAdapter.Fill(dataset, "Products");
SqlCommandBuilder bldr = newSqlCommandBuilder(dataAdapter);

DataTable dataTable = dataset.Tables[0];
dgCustomer.DataSource = dataTable;
dgCustomer.DataBind();
}

when i run this code, error like this appear :

Server Error in '/Registeration' Application.

SQL Server does not exist or access denied.

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: SQL Server does not exist or access denied.

Source Error:

Line 41: DataSet dataset = new DataSet();
Line 42:
Line 43: dataAdapter.Fill(dataset, "Products");
Line 44: SqlCommandBuilder bldr = new SqlCommandBuilder(dataAdapter);
Line 45:


Source File:e:\asp.net\registeration\register.aspx.cs Line:43

Stack Trace:

[SqlException: SQL Server does not exist or access denied.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState)
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
Registeration.WebForm1.Page_Load(Object sender, EventArgs e) in e:\asp.net\registeration\register.aspx.cs:43
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()



Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

how can i solve this problem? thank you...

Either the connectionstring is invalid or you didn't start the SQL service.

Start | Administrative tools | Services | Find the service and start it.

Regards

No comments:

Post a Comment