SqlBulkCopy.BatchSize Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.
public:
property int BatchSize { int get(); void set(int value); };
public int BatchSize { get; set; }
member this.BatchSize : int with get, set
Public Property BatchSize As Integer
Property Value
The integer value of the BatchSize property, or zero if no value has been set.
Examples
The following console application demonstrates how to bulk load data in batches of 50 rows. For an example illustrating how BatchSize works with a transaction, see Transaction and Bulk Copy Operations.
Important
This sample will not run unless you have created the work tables as described in Bulk Copy Example Setup.
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.
Remarks
A batch is complete when BatchSize rows have been processed or there are no more rows to send to the destination data source.
Zero (the default) indicates that each WriteToServer operation is a single batch.
If the SqlBulkCopy instance has been declared without the UseInternalTransaction option in effect, rows are sent to the server BatchSize rows at a time, but no transaction-related action is taken. If UseInternalTransaction is in effect, each batch of rows is inserted as a separate transaction.
The BatchSize property can be set at any time. If a bulk copy is already in progress, the current batch is sized according to the previous batch size. Subsequent batches use the new size. If the BatchSize is initially zero and changed while a WriteToServer operation is already in progress, that operation loads the data as a single batch. Any subsequent WriteToServer operations on the same SqlBulkCopy instance use the new BatchSize.