问题描述
当使用 ado.net 并在单个事务中创建到 MS SQL Server 数据库的多个连接(使用 System.Transactions.TransactionScope)时,System.Transactions 是否将事务从轻量级事务管理器提升到分布式事务协调器(Vista 上的内核事务协调器),即使所有连接对象的连接字符串都相同?
When using ado.net, and creating multiple connections to a MS SQL Server database within a single transaction (using System.Transactions.TransactionScope), does System.Transactions elevate the transaction from the lightweight transaction manager to the distributed transaction coordinator (kernel transaction coordinator on Vista), even if the connection strings are the same for all of the connection objects?
文档在这种特定情况下有些含糊不清.它表示如果在事务期间向服务器打开另一个连接,则事务将被提升,但它没有说明它是一直这样做还是仅在连接字符串不同时才这样做.如果连接字符串相同,它会提升事务对我来说没有意义,但如果是这样,它基本上会使轻量级事务管理器完全无用,IMO.
The documentation is somewhat ambiguous on this specific situation. It says the transaction will get elevated if another connection is opened to the server during the transaction but it doesn't say if it does that all the time or only if the connection string is different. It doesn't make sense to me that it would elevate the transaction if the connection string is the same, but if it does, it basically makes the lightweight transaction manager completely useless, IMO.
推荐答案
不幸的是,在当前版本中,它总是提升事务.
In the current version it always elevates the transaction, unfortunately.
正如您所说,TransactionScope 的用处比其他情况要少得多.我相信有计划在未来的版本中改变这一点.
Which as you say, makes TransactionScope a lot less useful than it otherwise would be. I believe there are plans to change this in a future version.
这篇关于单个事务下具有相同连接字符串的多个连接,提升事务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!