因此,我希望在一个SqlTransaction中使用多个SqlConnections。我知道我可以只使用一个连接,但最终在每个连接中都有大量新声明的无用变量(在连接完成后),并且我需要程序尽可能快地停留。
我将每个连接都放在一个using语句中。
我使用的是最新的.NET和SQL Server2008 R2。
有可能吗?
另外,我已经看过了:
How to use a single SqlTransaction for multiple SqlConnections in .NET?
没有人回答这个问题,平台已经过时了。
发布于 2013-02-28 09:01:22
你链接的问题有我要给你的答案,TransactionScope。
这样做的目的是让您的连接自动加入已经存在的事务。
using(System.Transacation.TransactionScope myScope = new TransactionScope()){
//all of your sql connections and work in here
//call this to commit, else everything will rollback
myScope.Complete();
}在这里了解更多事务作用域:
http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx
如果这不能回答你的问题,那么我完全误解了它。
https://stackoverflow.com/questions/15123700
复制相似问题