Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 2.12 KB

multiple-bulk-copy-operations.md

File metadata and controls

33 lines (25 loc) · 2.12 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic dev_langs
Multiple bulk copy operations
Describes how to do multiple bulk copy operations of data into an instance of SQL Server using the SqlBulkCopy class.
David-Engel
davidengel
v-kaywon
08/15/2019
sql
connectivity
conceptual
csharp

Multiple bulk copy operations

[!INCLUDEDriver_ADONET_Download]

You can perform multiple bulk copy operations using a single instance of a xref:Microsoft.Data.SqlClient.SqlBulkCopy class. If the operation parameters change between copies (for example, the name of the destination table), you must update them prior to any subsequent calls to any of the WriteToServer methods, as demonstrated in the following example. Unless explicitly changed, all property values remain the same as they were on the previous bulk copy operation for a given instance.

Note

Performing multiple bulk copy operations using the same instance of xref:Microsoft.Data.SqlClient.SqlBulkCopy is usually more efficient than using a separate instance for each operation.

If you perform several bulk copy operations using the same xref:Microsoft.Data.SqlClient.SqlBulkCopy object, there are no restrictions on whether source or target information is equal or different in each operation. However, you must ensure that column association information is properly set each time you write to the server.

Example

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 located in the same SQL Server instance, it is easier and faster to use a Transact-SQL INSERT … SELECT statement to copy the data.

[!code-csharpDataWorks SqlBulkCopy_._ColumnMappingOrdersDetails#1]

Next steps