Hey,
I've been trying to work this out for a while now. We have a reporting system that calls reports that can be pretty huge. Some users give up and close their browser thinking the process has failed. This leaves the query running on the server. What I want to do is kill the query when the user closes the browser.
I first thought I'd create an async db connection and poll the isCompleted flag like so:
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 = ...
Go to the complete details ...