简体   繁体   中英

Does SqlBulkCopy Enlist in Ambient Transaction?

I can't seem to find a definitive answer on this. I have a SqlBulkCopy operation that is wrapped in a TransactionScope with a number of other operations.

I am aware of overloads in the SqlBulkCopy constructor that allow passing a SqlTransaction object. Assuming I am not passing a transaction in the constructor, will the command automatically participate in the ambient transaction created by the TransactionScope?

I've done some testing, and it appears that SqlBulkCopy does, in fact, honor an ambient transaction, at least in .Net 4.5.

To test, I did a SqlBulkCopy operation while debugging, and verified that the rows made it to the database (via a NOLOCK/dirty read query). I then threw an exception on the next line of code, and allowed the TransactionScope to roll back. I then verified that the rows were no longer in the database.

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