none
SqlCommand.Cancel() documentation for 2.0 contains warning absent from 3.5; as well as vague/ambiguous warnings and contradictory example RRS feed

  • Question

  • The .NET 2.0 MSDN Documentation of the SqlCommand.Cancel method (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.cancel%28VS.80%29.aspx) contains the firm warning "The Cancel method cannot be used to cancel a pending asynchronous operation."

    The updated documentation, which contains no other discernable content differences, is absent of the warning (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.cancel.aspx).

    I have found several reports of users using SqlCommand.BeginExecuteReaderAsync(), calling SqlCommand.Cancel(), followed by EndExecuteReader() (as per the typical convention of working with Begin/End async methods that issue an IAsyncRequest) with the expected results that the Command is cancelled and the worker thread throws an "operation has been cancelled" error during the call to EndExecuteReader() method.

    My question is: is Cancel() safe to call provided that EndExecuteReader() is called, despite the warning in the docuementaiton--OR--to safely execute a cancellable SqlCommand are you required to manually create seperate worker threads which use the blocking ExecuteReaderAsync() method as per the MSDN example?
    • Edited by S Wolfe Wednesday, April 22, 2009 12:41 PM Correction: EndExecuteReaderAsync -> EndExecuteReader
    Tuesday, April 21, 2009 10:23 PM