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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With