SqlCommand.Cancel() method does not always work

  • I have a web application that asynchronously executes a sql query. While the query is executing there is a page that displays a cancel button that causes SqlCommand.Cancel() to be executed.

    If the user presses the cancel button shortly after the query is launched, the command object cancels the query. However, if the query goes on for a long time before the cancel button is pressed, the cancel button seems to have no effect.

    I understand that he Cancel() method is more like a RequestCancel(), but I have no idea why the cancel request would fail on SQL Server. Is there a timeout somewhere, perhaps on the SqlCommand object? Has SQL Server gone too far along in the query process to be able to stop? Perhaps Cancel() should always work and the issue is my local network settings.

    Any ideas as to why this happens, or how I can make the cancel process more robust?

    Thanks.

    DR

  • The command will stop the execution of the operation and will be followed by a rollback which can take a long time - depending on the size of the data being processed.

    ML

    ---
    Matija Lah, SQL Server MVP
    http://milambda.blogspot.com

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply