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

发布于 2024-11-11 08:58:46 字数 626 浏览 1 评论 0原文

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

稍后在内部事务范围中,我需要检查父事务范围的 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))
}

是可能的。

In a parent transaction scope, i have the TransactionScopeOption of Required.

Later on in a inner transaction scope, i need to check the TransactionScopeOption of the parent transaction scope.

How is this possible..

Example

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))
}

is this possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纵性 2024-11-18 08:58:46

这是不需要的。

如果“父级”TransactionScope必需,则嵌套的事务范围将已注册到事务中。

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

唯一的例外是,如果您将嵌套的 TransactionScope 显式设置为 RequiresNew,则新事务将启动。

This is not needed.

If the "parent" TransactionScope is Required, the nested one will be enrolled it the transactions already.

If it isn't, the nested one will not automatically become "required".

The only exception is if you explicitly set the nested TransactionScope to RequiresNew, when a new transaction will start.

染柒℉ 2024-11-18 08:58:46

从您对@Oded答案的评论来看,您似乎希望

  • MS SQL连接参与System.Transactions.Transactions
  • MySQL连接而不参与

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

AutoEnlist=False;

到您的 MySQL 连接字符串

如果 AutoEnlist 设置为 true(默认值),则连接
使用 TransactionScope 打开参与此范围,它提交
当范围提交并回滚(如果 TransactionScope 不这样做)时
犯罪。但是,此功能被认为是安全敏感的,并且
因此不能在中等信任环境中使用。

Judging from your comments to @Oded's answer, you seem to want

  • MS SQL connections to participate in System.Transactions.Transactions
  • MySQL connections to not participate

To get that behavior, you just need to append

AutoEnlist=False;

to your MySQL connection string:

If AutoEnlist is set to true, which is the default, a connection
opened using TransactionScope participates in this scope, it commits
when the scope commits and rolls back if TransactionScope does not
commit. However, this feature is considered security sensitive and
therefore cannot be used in a medium trust environment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文