Ian*_*est 5 c# sql sqltransaction
所以我有多个SqlConnections我想要在一个中使用SqlTransaction.我知道我只能使用一个连接,但最终在每个连接中都有大量新声明和无用(在连接完成后)变量,并且我需要程序尽可能快地保持.
我在using声明中有每个Connection .
我使用的是最新的.NET和SQL Server 2008 R2.
可能吗?
另外,我已经看过了:
如何在.NET中为多个SqlConnections使用单个SqlTransaction?
没有人回答这个问题,平台已经过时了.
Mik*_* C. 13
你链接的问题有我给你的答案,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();
}
Run Code Online (Sandbox Code Playgroud)
在这里更多地查看transactionscope:
http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx
如果这不能回答你的问题,那么我就完全误解了它.