Saturday, March 24, 2012

Abort SQL query when aborting callback

Hi,

I have got a page that depends on database queries that may take a couple of minutes to complete.
The page shows an UpdateProgress element and the idea is to add an "abort" button to it.
As far as I remember it should be easy to abort the browser callback.

Ideally I would like to have the database query/command aborted too to prevent a waste of precious resources (SQL Server 2005).

I wonder what will happen to the orphan callback after it has been aborted.
If I am lucky, what happens is the following:

1. When the user aborts the callback, the HttpRequest is destroyed.
2. The keep-alive mechanism allows the web server to detect that the request under process is now orphan.
3. The relevant Page object is then destroyed.
4. Similarly, SQL Server looses contact with the "consumer", that is the Page, and automatically aborts the query.

If this is not the case, is there a way to obtain the same result?

Thanks in advance,

Paolo

Here are some sample codes to abort asynchronous post back through javascript for your reference.

<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
function AbortPostBack() {
if (prm.get_isInAsyncPostBack()) {
prm.abortPostBack();
}
}
</script>

Wish the above can help you.


Thanks. What I am asking is if there is a way of cancelling the SQL query run by the call.

When a call is aborted the Response.IsClientConnected property value will become false. So I think what you need to do is to poll for the Response.IsClientConnected value and abort the query when it returns false (using SqlCommand.Cancel). This also means that you need to execute your query asynchronously.


I am facing similar problem.I try to use "Response.IsClientConnected".ut I found that it always returns "true" ( seems to be a bug).I am using IIS 6.

Is there any other work around for it ?

Thanks,

Vijay

No comments:

Post a Comment