为什么 TransactionScope 不回滚分布式事务?

发布于 2024-09-28 01:31:54 字数 322 浏览 1 评论 0原文

我正在使用名为 ECO 的对象持久性框架来将数据更新到 SQL Server。我注意到,如果我创建一个 TransactionScope,然后在第一个事务提交之后但在第二个事务提交之前故意抛出异常,则第一个数据库会更新,而第二个数据库不会更新。

我认为一旦分布式事务协调器在主数据库上运行,我只需围绕大量更新创建 TransactionScope 就可以了?

任何人都可以想到为什么这会允许更新第一个数据库但不更新第二个数据库的情况吗?

I am using an object persistence framework called ECO for updating data to SQL Server. I've noticed that if I create a TransactionScope and then deliberately throw an exception after my first transaction has committed but before my second has committed the first database is updated and the 2nd is not.

I thought that simply creating the TransactionScope around the numerous updates is all I had to do once the distributed transaction coordinator is running on the main DB?

Can anyone think of any reason why this would per permitting a scenario where the first DB is updated but not the second?

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

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

发布评论

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

评论(1

此生挚爱伱 2024-10-05 01:31:54

知道了!

ECO 支持以下数据库...

  1. BlackFish
  2. DB2
  3. FireBird
  4. Mimer
  5. MySql
  6. NexusDB
  7. Oracle
  8. SQLite
  9. SQLServer
  10. Sybase
  11. Borland 数据提供者
  12. Borland 数据库 eXpress (DBX)

今天早上我记得其中一些不支持连接池,因此在抽象 PersistenceMapper 类上 ECO 有实现了自己的连接池。这就是发生的事情

  1. 应用程序启动
  2. 我选择将我的对象映射信息存储在数据库本身中,因此ECO获得一个连接并读取该映射信息
  3. ECO将连接返回到池,但它自己的池
  4. 我稍后启动一个分布式事务
  5. 我将我的对象更新到数据库
  6. ECO 从其自己的池中检索连接

因此,该连接未登记在当前的分布式事务中。考虑到 SqlConnection 进行自己的池化,将 PersistenceMapperSqlServer.MaxPoolSize 设置为 0 是可以接受的。

现在它使用 SqlConnection 组件来处理连接的创建/销毁,该组件不仅池化连接,而且还正确处理分布式事务!

我已写信给开发人员,让他们知道他们应该将此属性标记为过时。

Got it!

ECO supports the following databases...

  1. BlackFish
  2. DB2
  3. FireBird
  4. Mimer
  5. MySql
  6. NexusDB
  7. Oracle
  8. SQLite
  9. SQLServer
  10. Sybase
  11. Borland data provider
  12. Borland database eXpress (DBX)

I remembered this morning that some of these don't support connection pooling, so on an abstract PersistenceMapper class ECO has implemented its own connection pooling. This is what was happening

  1. App starts
  2. I have opted to store my object mapping info in the DB itself, so ECO gets a connection and reads that mapping info
  3. ECO returns the connection to the pool, but its OWN pool
  4. I later start a distributed transaction
  5. I update my objects to the database
  6. ECO retrieves a connection from its own pool

As a consequence the connection is not enlisted in the current distributed transaction. Considering SqlConnection does its own pooling it was acceptable to set PersistenceMapperSqlServer.MaxPoolSize to ZERO.

Now it uses the SqlConnection component to deal with the creation/disposal of Connections, not only does that component pool the connections but it also deals with distributed transactions properly too!

I've written to the developers to let them know that they should mark this property obsolete.

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