Does SqlBulkCopy Enlist in Ambient Transaction?

I cannot find a definitive answer to this. I have a SqlBulkCopy operation that is wrapped in a TransactionScope with a number of other operations.

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

+3


source to share


1 answer


I've done some testing and it seems that SqlBulkCopy really deserves an external transaction, at least in .Net 4.5.



To test, I performed a SqlBulkCopy operation while debugging and verified that the rows did so in the database (via a NOLOCK / dirty read request). Then I threw an exception on the next line of code and allowed the Transco transaction to be canceled. Then I checked that the rows are no longer in the database.

+3


source







All Articles