SqlCommand::BeginExecuteNonQuery Method ()
Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this SqlCommand.
Assembly: System.Data (in System.Data.dll)
public: [HostProtectionAttribute(SecurityAction::LinkDemand, ExternalThreading = true)] IAsyncResult^ BeginExecuteNonQuery()
Any error that occurred while executing the command text.
A timeout occurred during a streaming operation. For more information about streaming, see SqlClient Streaming Support.
The EndExecuteNonQuery method to finish the operation. The method returns immediately (CommandTimeout has no effect on ), but until the code executes the corresponding EndExecuteNonQuery method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same SqlCommand object. Calling the EndExecuteNonQuery before the command's execution is completed causes the SqlCommand object to block until the execution is finished.method starts the process of asynchronously executing a Transact-SQL 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
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 IsCompleted property of the IAsyncResult returned by the method; or wait for the completion of one or more commands using the AsyncWaitHandle property of the returned IAsyncResult.
The following console application creates updates data within the AdventureWorks sample database, doing its work asynchronously. In order to emulate a long-running process, this example inserts a WAITFOR statement in the command text. Normally, you would not take efforts to make your commands run slower, but doing this in this case makes it easier to demonstrate the asynchronous behavior.
Available since 2.0