TransactionScope、linq 和奇怪的事务管理器问题(HRESULT:0x8004D024)

发布于 2024-07-17 12:39:18 字数 1275 浏览 8 评论 0原文

我有一个服务级别方法,它对数据库进行很少的更改,并且我希望它们使用事务控制。 这些方法可以执行以下操作: - LINQ SubmitChanges() 功能 - 调用 StoredProcedures

组件用户可以将一组此类基本操作组合成更大的操作。

我看到有一个很好的类 TransactinScope 并尝试使用它:

using (TransactionScope transaction = new TransactionScope())
{
     content = repository.CreateBaseContent(content);
     result = repository.CreateTreeRelation(content, parent.Id, name);
     transaction.Complete();
}

public baseContent CreateBaseContent(baseContent content)
{
       EntityContext.baseContents.InsertOnSubmit(content);
       EntityContext.SubmitChanges();

       return content;
}

public CreateTreeRelation (params)
{
// do StoredProcedure call here via LINQ
}

我的假设是在外层上可以添加另一个级别的事务范围。 相反,我遇到以下错误:

事务管理器已禁用其对远程/网络事务的支持。 (HRESULT 异常:0x8004D024)

我对 MS SQL 2005 和 Microsoft 开发服务器使用相同的(Vista Ultimate)机器。 从单元测试来看,一切正常。 TransactionScope 评论时相同。

我试图玩弄 DTC 的安全性 (http://support.microsoft.com/kb/899191< /a>),当我设置接受所有入站和出站事务时,出现以下错误消息:

调用 COM 组件已返回错误 HRESULT E_FAIL。

在调试过程中,我发现在SubmitChanges中,Linq Entity Context具有Property Transaction IS NULL(!!),并且System.Transactions.Transaction.Current具有打开的事务

I have a service level methods, which make few changes to database and I want them to use transaction control. Such methods can do following:
- LINQ SubmitChanges() functionality
- Calls to StoredProcedures

Component users can combine set of such elementary operations into something bigger.

I see that there is nice class TransactinScope and trying to use it:

using (TransactionScope transaction = new TransactionScope())
{
     content = repository.CreateBaseContent(content);
     result = repository.CreateTreeRelation(content, parent.Id, name);
     transaction.Complete();
}

public baseContent CreateBaseContent(baseContent content)
{
       EntityContext.baseContents.InsertOnSubmit(content);
       EntityContext.SubmitChanges();

       return content;
}

public CreateTreeRelation (params)
{
// do StoredProcedure call here via LINQ
}

My Assumption was that on outer layers it would be possible to add another level of transaction scope. Instead, I am having following error:

The transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D024)

I am using same (Vista Ultimate) machine for MS SQL 2005 and microsoft development server. From unit tests everything works fine. Same when TransactionScope commented.

I was trying to play with security for DTC (http://support.microsoft.com/kb/899191) and when I set to acccept all inbound and outbound transactions, I have following error message:

Error HRESULT E_FAIL has been returned from a call to a COM component.

During debug, I discovered that in SubmitChanges, Linq Entity Context has Property Transaction IS NULL(!!), and System.Transactions.Transaction.Current has open transaction

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

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

发布评论

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

评论(2

2024-07-24 12:39:18

我认为您也可以使用 TransactionScope,只要您将数据上下文传递给您打开的相同连接即可。

TransactionScope 遇到的另一个问题是它不关心连接字符串是否相同,执行第二个 .Open 会将事务提升为分布式事务。 然后您必须处理相关的配置,以及它没有使用该情况所需的轻量事务这一事实。

I think you can also use TransactionScope as long as you pass the datacontexts the same connection you .Open.

Another issue you get with TransactionScope is that it doesn't care if the connection string is the same, doing a second .Open will elevate the transaction to a distributed transaction. And then you have to deal with the related configuration, and also the fact that it isn't using the light transaction that is what is needed for that case.

可爱暴击 2024-07-24 12:39:18

发生问题是因为 Linq Datacontext 是在 transactionscope 之前创建的。

解决方案是将自己的事务控制添加到 LINQ 数据上下文。

Connection.Open()
Transaction = Connection.BeginTransaction();

和计数器来维护嵌套调用。

Issue happened because Linq Datacontext was created before transactionscope.

Solution was to add own transaction control to LINQ datacontext.

Connection.Open()
Transaction = Connection.BeginTransaction();

and counters to maintain nested calls.

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