TransactionScope:情况变得更好了吗?

发布于 2024-07-29 01:52:15 字数 337 浏览 4 评论 0原文

当 TransactionScope 首次推出时,我在让它在我的开发机器 (XP) 和我们的数据库服务器 (Windows Server 2003) 之间工作时遇到了一些严重的问题。

当我进一步研究时,这似乎是一个棘手且普遍的问题,有可能在生产中成为令人头痛的问题,因此我决定不以这种方式处理事务(尽管我非常喜欢这种语法并且我真的很想要它)上班)。

这些问题是否仍然存在或者可以安全使用吗? 您现在经常使用它没有问题吗?

多谢!

注意:已经过去很长时间了,但我认为这个问题与分布式事务协调器有关。 我摆弄了它很长时间,但始终无法让它工作。

When TransactionScope first came out, I ran into some serious issues getting it to work between my dev machine (XP) and our database server (Windows Server 2003).

When I looked into it more, this appeared to be a tricky and widespread issue that had a chance of becoming a headache in production, so I decided not to handle transactions this way (even though I like the syntax a lot and I really wanted it to work).

Are these problems still out there or is this safe to use? Do you use this regularly now without issues?

Thanks a lot!

Note: It has been a long time now, but I think the issue had something to do with Distribute Transaction Coordinator. I fiddled with it for a long time and was never able to get it working.

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

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

发布评论

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

评论(3

深海里的那抹蓝 2024-08-05 01:52:15

Rick Strahl 在此处发表了一篇关于事务范围和 LINQ to SQL 的精彩文章。 它的上下文更多的是 LINQ to SQL,但我认为有一些适用的原则可以帮助您解决问题。

编辑:为了更具体地回答你的问题,以下是斯特拉尔对 TransactionScope 的看法:

传统上,TransactionScope 是分布式事务协调器 (DTC) 的 .NET 包装器,但它的功能有所扩展。 一个问题是,DTC 在资源使用方面相当昂贵,并且它要求 DTC 服务实际上在计算机上运行(这是另一个在客户端安装上特别麻烦的服务)。

但是,最近对 TransactionScope 和 SQL Server 客户端驱动程序的更新使得只要您针对单个数据库运行并使用单个一致的连接字符串,就可以使用 TransactionScope 类及其提供的易用性,而无需 DTC< /p>

Rick Strahl has a great post about transaction scope and LINQ to SQL here. Its context is more LINQ to SQL, but I think that there are some principles that apply which could help you solve your question.

EDIT: to more specifically answer your question, here's what Strahl has to say about TransactionScope:

Traditionally TransactionScope was a .NET wrapper around the Distributed Transaction Coordinator (DTC) but it’s functionality has expanded somewhat. One concern is that the DTC is rather expensive in terms of resource usage and it requires that the DTC service is actually running on the machine (yet another service which is especially bothersome on a client installation).

However, recent updates to TransactionScope and the SQL Server Client drivers make it possible to use TransactionScope class and the ease of use it provides without requiring DTC as long as you are running against a single database and with a single consistent connection string

Smile简单爱 2024-08-05 01:52:15

我已经使用 TransactionScope 一年多了,没有任何问题。 然而,该应用程序是一个内部应用程序,用户数量很少。 此外,数据库和应用程序驻留在同一服务器上。

以下是有关 TransactionScope 的一些信息以及在何处查找更多信息:
每当您创建 TransactionScope 对象时,它都会启动一个轻量级事务。 那么只要您使用支持轻量级事务的单个连接/资源,事务就会由资源管理器处理,消耗尽可能少的资源,并且性能非常好。 当您将第二个连接/资源添加到事务范围时,事务管理器将自动升级为 OleTx 事务管理器,它可以使用 COM+ DTC 技术处理分布式事务。 如果与不支持轻量级事务的资源管理器(例如 SQL Server 7/2000、Oracle 和其他 RDBMS)进行单一连接,也会发生这种情况。

以下两个资源可能会对您有所帮助:

“Microsoft Windows Server 2003 Service Pack 1 (SP1) 和 Microsoft Windows XP Service Pack 2 (SP2) 包括许多与安全相关的更新和更改。其中一些更改会影响 Microsoft分布式事务协调器 (MSDTC) 服务。”
Windows Server 2003 Service Pack 1 和 Windows XP Service Pack 2 中分布式事务协调器服务的新功能< /a>

Juval Lowy 关于 System.Transactions 的白皮书:
在Microsoft .NET Framework 2.0 版

I have been using TransactionScope for over a year now without any issues. However, the application is an internal application with a very small number of users. Also, the database and application reside on the same server.

Here is some information on TransactionScope and where to look for more information:
Whenever you create a TransactionScope object it starts a lightweight transaction. Then as long as you use a single connection/resource that supports lightweight transactions, the transaction will be handled by the resource manager consuming as little resources as possible with very good performance. When you add a second connection/resource into the transaction scope the transaction manager will automatically be promoted to an OleTx Transaction Manager, which can handle distributed transactions by using the COM+ DTC technologies. This will also happen with a single connection to a resource manager that doesn't support lightweight transactions such as SQL Server 7/2000, Oracle and other RDBMSs.

Here are two resources that may be able to help you out:

"Microsoft Windows Server 2003 Service Pack 1 (SP1) and Microsoft Windows XP Service Pack 2 (SP2) include many security-related updates and changes. Some of these changes affect the Microsoft Distributed Transaction Coordinator (MSDTC) service."
New functionality in the Distributed Transaction Coordinator service in Windows Server 2003 Service Pack 1 and in Windows XP Service Pack 2

and

Juval Lowy's whitepaper on System.Transactions:
Introducing System.Transactions in the Microsoft .NET Framework version 2.0

沐歌 2024-08-05 01:52:15

关于 TransactionScope 仍然存在问题。 在我当前的项目中,我们不定期地遇到“无法加入分布式事务”异常和 TransactionInDoubtException。 这两个异常都与 TransactionScope 相关。 针对这两个异常的一种解决方法是使用单个 oracle 连接(当然如果适用)。
请阅读以下内容:避免不必要的升级到分布式事务

有关性能影响的信息,请阅读我的文章:使用 TransactionScope 的性能影响

There are still issues regarding TransactionScope. In my current project we are at irregular intervals running into both “Unable to enlist in a distributed transaction” exceptions and TransactionInDoubtException. Both exceptions related to TransactionScope. One workaround for both exceptions is to use a single oracle connection (if applicable of course).
Read about this in: Avoid unwanted Escalation to Distributed Transactions

For information on performance impact please read my post: Performance impact using TransactionScope

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