简体   繁体   English

SqlBulkCopy是否参与环境事务?

[英]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. 我有一个SqlBulkCopy操作,该操作与许多其他操作包装在TransactionScope中。

I am aware of overloads in the SqlBulkCopy constructor that allow passing a SqlTransaction object. 我知道SqlBulkCopy构造函数中的重载,该重载允许传递SqlTransaction对象。 Assuming I am not passing a transaction in the constructor, will the command automatically participate in the ambient transaction created by the TransactionScope? 假设我没有在构造函数中传递事务,该命令是否将自动参与TransactionScope创建的环境事务?

I've done some testing, and it appears that SqlBulkCopy does, in fact, honor an ambient transaction, at least in .Net 4.5. 我已经进行了一些测试,并且看来SqlBulkCopy实际上确实支持环境事务,至少在.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). 为了进行测试,我在调试时执行了SqlBulkCopy操作,并验证了这些行已将其存储到数据库中(通过NOLOCK /脏读取查询)。 I then threw an exception on the next line of code, and allowed the TransactionScope to roll back. 然后,我在下一行代码中引发了一个异常,并允许TransactionScope回滚。 I then verified that the rows were no longer in the database. 然后,我确认行不再在数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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