System.Data.SqlClient.SqlCommand.Cancel Method

Tries to cancel the execution of a System.Data.SqlClient.SqlCommand.

Syntax

public override void Cancel ()

Remarks

If there is nothing to cancel, nothing occurs. However, if there is a command in process, and the attempt to cancel fails, no exception is generated.

In some, rare, cases, if you call SqlCommand.ExecuteReader then call SqlDataReader.Close (implicitily or explicitly) before calling SqlCommand.Cancel, and then call SqlCommand.Cancel, the cancel command will not be sent to SQL Server and the result set can continue to stream after you call SqlConnection.Close. To avoid this, make sure that you call SqlCommand.Cancel before closing the reader or connection.

Requirements

Namespace: System.Data.SqlClient
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0