The SqlRowCopied
event raised after the number of row in the NotifyAfter has been processed.
The following example sets NotifyAfter
property so that the event handler is called after every 200 rows copied to the table.
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connectionString))
{
// SET SqlRowsCopied event.
bulkCopy.SqlRowsCopied += (sender, args) => { /* code */ };
bulkCopy.NotifyAfter = 4000;
bulkCopy.DestinationTableName = "TheDestinationTable";
bulkCopy.WriteToServer(reader);
}
The receipt of a SqlRowsCopied event does not imply that any rows have been sent to the server or committed.
SqlBulkCopy.Close
or SqlConnection.Close
from this event, if do so, it will throw an InvalidOperationException
exception, and the SqlBulkCopy object state will not change.Abort
property of the SqlRowsCopiedEventArgs
.