DataReader associated with this Command which must be closed

Mar 23 2020 8:55 AM
There is already an open DataReader associated with this Command which must be closed first.
 
Line 33: SqlDataAdapter da = new SqlDataAdapter(query, con);
Line 34: DataSet ds = new DataSet();
Line 35: da.Fill(ds);
Line 36: GridView1.DataSource = ds;
Line 37: GridView1.DataBind();
Stack Trace:
[InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.]
System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command) +1642350
System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command) +91
System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async) +274
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) +119
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +65
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +170
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +43
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +12
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +140
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +138
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +89 cssapp.WebForm1.rep_bind() in C:\Users\Ravi\Documents\Visual Studio 2019\Project\cssapp\cssapp\WebForm1.aspx.cs:35
cssapp.WebForm1.Button1_Click(Object sender, EventArgs e) in C:\Users\Ravi\Documents\Visual Studio 2019\Project\cssapp\cssapp\WebForm1.aspx.cs:51
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9784114 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +211
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1696

Answers (4)