在子事务管理器中查找父事务范围的TransactionScopeOption

时间:2011-06-01 05:46:17

标签: transactionscope

在父事务范围中,我的TransactionScopeOption为Required。

稍后在内部事务范围中,我需要检查父事务范围的TransactionScopeOption。

这怎么可能......

示例

Parent : using (TransactionScope transactionScopeParent = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
{
....
method()
}

method()
{
here i need to check the TransactionScopeOption of this transaction scope's parent one and then set this transaction scope to be having the same TransactionScopeOption.

using (TransactionScope transactionScopeChild = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
}

这是可能的。

2 个答案:

答案 0 :(得分:0)

这不是必需的。

如果“父级”TransactionScopeRequired,则嵌套式帐户将在已注册的交易中注册。

如果不是,嵌套的将不会自动变为“必需”。

唯一的例外是,如果您在新事务开始时将嵌套TransactionScope显式设置为RequiresNew

答案 1 :(得分:0)

从您对@ Oded的答案的评论来看,您似乎想要

  • MS SQL连接以参与System.Transactions.Transaction s
  • MySQL连接不参与

要获得该行为,您只需要附加

  

AutoEnlist = FALSE;

MySQL connection string

  

如果AutoEnlist设置为true,这是默认连接   使用TransactionScope打开参与此范围,它提交   当范围提交并回滚时TransactionScope没有   承诺。但是,此功能被认为是安全敏感的   因此不能在中等信任环境中使用。

相关问题