SqlBulkCopy::Close Method ()


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Closes the SqlBulkCopy instance.

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

void Close()

After you call a Close on the SqlBulkCopy object, no other operation will succeed. Calls to the WriteToServer method will throw an InvalidOperationException.

Calling the Close method from the SqlRowsCopied event causes an InvalidOperationException to be thrown.

Note that open SqlBulkCopy instances are closed implicitly at the end of a using block.

The following example uses the same SqlBulkCopy instance to add sales orders and their associated details to two destination tables. Because the AdventureWorks sales order tables are large, the sample reads only orders placed by a certain account number and bulk copies those orders and details to the destination tables. The Close method is used only after both bulk copy operations are complete.


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.

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

.NET Framework
Available since 2.0
Return to top