Hi,
possible the following solution works. Use the DataReader's ReadNext method see
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.nextresult.aspx
for details. Possible you should think of another solution. generate the reports on a daily base at night or whatever. Also i wanted to mention, that you only can stop the database server from processing your sp at some point, so possible the database query will continue to run. Depending on the SQL you are executing.
But here is an example:
private void CloseConnection(SqlConnection conn) {
if (conn.State != ConnectionState.Closed) {
conn.Close();
}
}
private void AddDataTable(SqlDataReader drResult, DataSet ds) {
DataTable dtResult = new DataTable();
dtResult.Load(drResult);
ds.Tables.Add(dtResult);
}
private void LoadData() {
SqlCommand cmdData = new SqlCommand("_Async_Sleep_Test_10");
cmdData.CommandType = CommandType.StoredProcedure;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["connstring_Async"].ConnectionString;
cmdData.Connection = conn;
conn.Open();
IAsyncResult asyResult = cmdData.BeginExecuteReader();
while (!asyResult.IsCompleted) {
if (!Response.IsClientConnected) {
cmdData.Cancel();
conn.Close();
Response.End();
}
}
SqlDataReader drResult = cmdData.EndExecuteReader(asyResult);
if (!drResult.HasRows) {
CloseConnection(conn);
return;
}
DataSet ds = new DataSet();
// adds the current result
AddDataTable(drResult, ds);
// iterate through all availabe results
while (drResult.NextResult()) {
// add each result
AddDataTable(drResult, ds);
}
// ds should now contain all datatables
CloseConnection(conn);
}