System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery Method

Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this System.Data.SqlClient.SqlCommand.


public IAsyncResult BeginExecuteNonQuery ()


An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking SqlCommand.EndExecuteNonQuery(IAsyncResult), which returns the number of affected rows.


The SqlCommand.BeginExecuteNonQuery method starts the process of asynchronously executing a tsql statement or stored procedure that does not return rows, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the SqlCommand.EndExecuteNonQuery(IAsyncResult) method to finish the operation. The SqlCommand.BeginExecuteNonQuery method returns immediately (SqlCommand.CommandTimeout has no effect on SqlCommand.BeginExecuteNonQuery), but until the code executes the corresponding SqlCommand.EndExecuteNonQuery(IAsyncResult) method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same System.Data.SqlClient.SqlCommand object. Calling the SqlCommand.EndExecuteNonQuery(IAsyncResult) before the command's execution is completed causes the System.Data.SqlClient.SqlCommand object to block until the execution is finished.

Note that the command text and parameters are sent to the server synchronously. If a large command or many parameters are sent, this method may block during writes. After the command is sent, the method returns immediately without waiting for an answer from the server--that is, reads are asynchronous.

Because this overload does not support a callback procedure, developers must either poll to determine whether the command has completed, using the IAsyncResult.IsCompleted property of the IAsyncResult returned by the SqlCommand.BeginExecuteNonQuery method; or wait for the completion of one or more commands using the IAsyncResult.AsyncWaitHandle property of the returned IAsyncResult.


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