简体   繁体   中英

Will SqlBulkCopy Close method commit/Dispose external transaction?

I have a SQL Bulk copy function which has following code to create a bulk copy instance.

 SqlBulkCopy bulkCopy = new SqlBulkCopy((SqlConnection) WorkConnection,
            SqlBulkCopyOptions.FireTriggers, (SqlTransaction) WorkTransaction);

"WorkTransaction" is an external transaction. What will happen to it

  1. If we use "using" block around the SqlBulkCopy. Will it dispose this external transaction ?
  2. If we call close function ( "bulkCopy.Close();"), will it commit/dispose external transaction ?

Any help would be appreciated!

Thanks

No. The point of supplying an external transaction to SqlBulkCopy is to allow other operations to be included in the transaction, so unless an error occurs, SqlBulkCopy will not terminate the transaction.

From the MS Doc :

You can specify an existing SqlTransaction object as a parameter in a SqlBulkCopy constructor. In this situation, the bulk copy operation is performed in an existing transaction, and no change is made to the transaction state (that is, it is neither committed nor aborted). This allows an application to include the bulk copy operation in a transaction with other database operations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM