This documentation is archived and is not being maintained.

SqlBulkCopy::SqlRowsCopied Event

Occurs every time that the number of rows specified by the NotifyAfter property have been processed.

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

public:
 event SqlRowsCopiedEventHandler^ SqlRowsCopied {
	void add (SqlRowsCopiedEventHandler^ value);
	void remove (SqlRowsCopiedEventHandler^ value);
}

Note that the settings of NotifyAfter and BatchSize are independent. Receipt of a SqlRowsCopied event does not imply that any rows have been sent to the server or committed.

You cannot call SqlBulkCopy.Close (Close) or SqlConnection.Close (Close) from this event. Doing this will cause an InvalidOperationException being thrown, and the SqlBulkCopy object state will not change. If the user wants to cancel the operation from the event, the Abort property of the SqlRowsCopiedEventArgs can be used. (See Transaction and Bulk Copy Operations (ADO.NET) for examples that use the Abort property.)

No action, such as transaction activity, is supported in the connection during the execution of the bulk copy operation, and it is recommended that you not use the same connection used during the SqlRowsCopied event. However, you can open a different connection.

The following console application demonstrates how to bulk load data using a connection that is already open. The NotifyAfter property is set so that the event handler is called after every 50 rows copied to the table.

In this example, the connection is first used to read data from a SQL Server table to a SqlDataReader instance. Note that the source data does not have to be located on SQL Server; you can use any data source that can be read to an IDataReader or loaded to a DataTable.

Important noteImportant

This sample will not run unless you have created the work tables as described in Bulk Copy Example Setup (ADO.NET). This code is provided to demonstrate the syntax for using SqlBulkCopy only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL INSERT … SELECT statement to copy the data.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: