【问题标题】:How to determine if SQLConnection belong to the current ambient transaction System.Transactions.Transaction.Current?如何判断 SQLConnection 是否属于当前环境事务 System.Transactions.Transaction.Current?
【发布时间】:2015-02-07 18:48:56
【问题描述】:

我想知道的是,给定的SQLConnection 是否在给定时间内登记当前环境事务,我的意思是,在调试时将一些东西放入手表中这让我知道当前环境事务是否登记了一个连接。我正在调试创建TransactionScope 类的多个实例的代码,并且在创建TransactionScope 的新实例之前,代码既不调用TransactionScope.Complete 也不调用TransactionScopeDispose。因此,如果我能知道给定的SQLConnection 是否被列入当前的ambient transaction 将会非常有用。

顺便说一句,TransactionScope 不是使用usingstatement 创建的,所以很难通过阅读代码知道SQLConnection 属于什么TransactionScope 实例。

【问题讨论】:

    标签: transactions transactionscope sqlconnection dts


    【解决方案1】:

    登记的事务存储在SqlInternalConnectionEnlistedTransaction field 中。该字段设置为here in the EnlistNonNull method。您可以通过反射访问该字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-09
      • 1970-01-01
      • 2011-03-09
      • 1970-01-01
      • 2015-08-24
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多