System.Data 2.0.0.0 System.Object System.IDisposable

Microsoft SQL Server includes a popular command-prompt utility named bcp for moving data from one table to another, whether on a single server or between servers. The class lets you write managed code solutions that provide similar functionality. There are other ways to load data into a SQL Server table (INSERT statements, for example), but offers a significant performance advantage over them.

The class can be used to write data only to SQL Server tables. However, the data source is not limited to SQL Server; any data source can be used, as long as the data can be loaded to a instance or read with a instance.

will fail when bulk loading a column of type into a SQL Server column whose type is one of the date/time types added in SQL Server 2008.

Lets you efficiently bulk load a SQL Server table with data from another source.

- Constructor
  2.0.0.0

  Because the connection is already open when the instance is initialized, the connection remains open after the instance is closed.

  If the argument is null, an is thrown.

  Initializes a new instance of the class using the specified open instance of .

  The already open instance that will be used to perform the bulk copy operation. If your connection string does not use Integrated Security = true, you can use to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string.
- Constructor
  2.0.0.0

  The connection is automatically closed at the end of the bulk copy operation.

  If is null, an is thrown. If is an empty string, an is thrown.

  Initializes and opens a new instance of based on the supplied . The constructor uses the to initialize a new instance of the class.

  The string defining the connection that will be opened for use by the instance. If your connection string does not use Integrated Security = true, you can use or and to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string.
- Constructor
  2.0.0.0

  You can obtain detailed information about all the bulk copy options in the topic.

  Initializes and opens a new instance of based on the supplied . The constructor uses that to initialize a new instance of the class. The instance behaves according to options supplied in the parameter.

  The string defining the connection that will be opened for use by the instance. If your connection string does not use Integrated Security = true, you can use or and to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string.
  A combination of values from the enumeration that determines which data source rows are copied to the destination table.
- Constructor
  2.0.0.0

  If options include UseInternalTransaction and the argument is not null, an InvalidArgumentException is thrown.

  For examples demonstrating how to use SqlBulkCopy in a transaction, see Performing a Bulk Copy Operation in a Transaction.

  Initializes a new instance of the class using the supplied existing open instance of . The instance behaves according to options supplied in the parameter. If a non-null is supplied, the copy operations will be performed within that transaction.

  The already open instance that will be used to perform the bulk copy. If your connection string does not use Integrated Security = true, you can use to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string.
  A combination of values from the enumeration that determines which data source rows are copied to the destination table.
  An existing instance under which the bulk copy will occur.
- Property
  2.0.0.0
  System.Int32 To be added.

  A batch is complete when rows have been processed or there are no more rows to send to the destination data source.

  Zero (the default) indicates that each operation is a single batch.

  If the instance has been declared without the option in effect, rows are sent to the server rows at a time, but no transaction-related action is taken. If is in effect, each batch of rows is inserted as a separate transaction.

  The 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 is initially zero and changed while a operation is already in progress, that operation loads the data as a single batch. Any subsequent operations on the same instance use the new .

  Number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.

- Property
  2.0.0.0
  System.Int32 To be added.

  If the operation does time out, the transaction is not committed and all copied rows are removed from the destination table.

  Number of seconds for the operation to complete before it times out.

- Method
  2.0.0.0
  System.Void

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

  Calling the method from the event causes an to be thrown.

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

  Closes the instance.

- Property
  2.0.0.0
  System.Data.SqlClient.SqlBulkCopyColumnMappingCollection To be added.

  If the data source and the destination table have the same number of columns, and the ordinal position of each source column within the data source matches the ordinal position of the corresponding destination column, the collection is unnecessary. However, if the column counts differ, or the ordinal positions are not consistent, you must use to make sure that data is copied into the correct columns.

  During the execution of a bulk copy operation, this collection can be accessed, but it cannot be changed. Any attempt to change it will throw an .

  Returns a collection of items. Column mappings define the relationships between columns in the data source and columns in the destination.

- Property
  2.0.0.0
  System.String To be added.

  If has not been set when is called, an is thrown.

  If is modified while a operation is running, the change does not affect the current operation. The new value is used the next time a method is called.

  is a three-part name (<database>.<owningschema>.<name>). You can qualify the table name with its database and owning schema if you choose. However, if the table name uses an underscore ("_") or any other special characters, you must escape the name using surrounding brackets as in ([<database>.<owningschema>.<name_01>]). For more information, see "Identifiers" in SQL Server Books Online.

  You can bulk-copy data to a temporary table by using a value such as tempdb..#table or tempdb.<owner>.#table for the property.

  Name of the destination table on the server.

- Property
  2.0.0.0
  System.Int32 To be added.

  This property is designed for user interface components that illustrate the progress of a bulk copy operation. It indicates the number of rows to be processed before generating a notification event. The property can be set at any time, even while a bulk copy operation is underway. Changes made during a bulk copy operation take effect after the next notification. The new setting applies to all subsequent operations on the same instance.

  If is set to a number less than zero, an is thrown.

  Defines the number of rows to be processed before generating a notification event.

- Event
  2.0.0.0
  System.Data.SqlClient.SqlRowsCopiedEventHandler

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

  You cannot call SqlBulkCopy.Close () or SqlConnection.Close () from this event. Doing this will cause an being thrown, and the object state will not change. If the user wants to cancel the operation from the event, the property of the can be used. (See Performing a Bulk Copy Operation in a Transaction for examples that use the 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 event. However, you can open a different connection.

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

- Method
  2.0.0.0
  System.Void

  Call Dispose when you are finished using the . The Dispose method leaves the in an unusable state. After calling Dispose, you must release all references to the so the garbage collector can reclaim the memory that the was occupying.

  For more information, see Cleaning Up Unmanaged Resources and Implementing a Dispose Method.

  Always call Dispose before you release your last reference to the . Otherwise, the resources it is using will not be freed until the garbage collector calls the object's Finalize method.

  Releases all resources used by the current instance of the class.

- Method
  2.0.0.0
  System.Void ``

  While the bulk copy operation is in progress, the associated destination is busy serving it, and no other operations can be performed on the connection.

  The collection maps from the columns to the destination database table.

  Copies all rows from the supplied array to a destination table specified by the property of the object.

  An array of objects that will be copied to the destination table.
- Method
  2.0.0.0
  System.Void ``

  All rows in the are copied to the destination table except those that have been deleted.

  While the bulk copy operation is in progress, the associated destination is busy serving it, and no other operations can be performed on the connection.

  The collection maps from the columns to the destination database table.

  Copies all rows in the supplied to a destination table specified by the property of the object.

  A whose rows will be copied to the destination table.
- Method
  2.0.0.0
  System.Void ``

  The copy operation starts at the next available row in the reader. Most of the time, the reader was just returned by or a similar call, so the next available row is the first row. To process multiple results, call on the data reader and call again.

  Note that using modifies the state of the reader. The method will call until it returns false, the operation is aborted, or an error occurs. This means that the data reader will be in a different state, probably at the end of the result set, when the operation is complete.

  While the bulk copy operation is in progress, the associated destination is busy serving it, and no other operations can be performed on the connection.

  The collection maps from the data reader columns to the destination database table.

  Copies all rows in the supplied to a destination table specified by the property of the object.

  A whose rows will be copied to the destination table.
- Method
  2.0.0.0
  System.Void `` ``

  Only rows in the that are in the states indicated in the argument and have not been deleted are copied to the destination table.

  If is specified, any , , and rows will also be copied to the server. No exception will be raised.

  While the bulk copy operation is in progress, the associated destination is busy serving it, and no other operations can be performed on the connection.

  The collection maps from the columns to the destination database table.

  Copies only rows that match the supplied row state in the supplied to a destination table specified by the property of the object.

  A whose rows will be copied to the destination table. A value from the enumeration. Only rows matching the row state are copied to the destination.