SQLTransaction,Transactionscope & IDBtransaction
What is the difference between SQLTransaction,Transactionscope & IDBtransaction in c#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
rupali patilPosted Jun 16, 2016, 3:42 AM
Vasanth NatarajanPosted Jun 15, 2016, 3:00 AM
Transaction
If anything goes wrong with any of the grouped statements, all changes need to be aborted. The process of reversing changes is called rollback in SQL Server terminology. If everything is in order with all statements within a single transaction, all changes are recorded together in the database. In SQL Server terminology, we say that these changes are committed to the database.
using (TransactionScope transactionScope = new TransactionScope())
{
try
{
orcmethod1() // Oracle DML operation
sqlmethod2() // Sql DML operation
orcmethod3() // Oracle DML operation
// transactionScope.complete()
// transactionScope.Dispose();
}
catch (TransactionException ex)
{
transactionScope.Dispose();
MessageBox.Show("Transaction Exception Occured");
}
}I'm entirely with you on the connection; that should be
using, and there is no need for the explicitClose(). The transaction is a little bit trickier; the code shown is certainly overkill at the moment, but it is not entirely defined thatDispose()should do a rollback. Actually, that is what tends to happen in every implementation I've looked at, but it is slightly vexing that evenDbTransaction(which most providers use) doesn't actually do this. Contrast toTransactionScopewhere it is explicitly defined that aDispose()without a commit counts as a rollback. Because of that, I tend to use (excuse the C#):Vinay SinghPosted Jun 15, 2016, 2:21 AM
http://stackoverflow.com/questions/1270981/refactoring-ado-net-sqltransaction-vs-transactionscope
http://stackoverflow.com/questions/542525/transactionscope-vs-transaction-in-linq-to-sql
http://www.eranachum.com/PermaLink,guid,6e26a414-6a87-47a6-b9c0-e3be26298852.aspx