Questions tagged [transactionscope]

TransactionScope is a .NET class used to mark a block of code as transactional. It uses an implicit programming model so transactions are managed by the infrastructure, rather than the developer. The class was introduced in .NET 2.0.

Description

The TransactionScope class is part of the System.Transactions namespace. Unlike the System.Transactions.Transaction class, which uses an explicit programming model, the TransactionScope class uses an implicit programming model, which simplifies how transactions are used in client code.

How to use it

To use TransactionScope, the developer simply creates a scope, does the transactional work and then indicates when the transaction is complete. There is no need to explicitly rollback the transaction in the case of an error.

 using(var scope = new TransactionScope())
 {
      // do database or other transactional work here
      scope.Complete();
 }

Inside the scope, resources are automatically enlisted in the ambient transaction so there is no need to manage the transaction directly. The transaction is automatically rolled back unless it is marked as complete before TransactionScope is disposed.

References

TransactionScope Class (MSDN)

1049 questions
0
votes
1 answer

Entity Framework SaveChanges(False) fails while using TransactionScope

The question asked on following link has a great answer under that as well but my problem starts after that. Using Transactions or SaveChanges(false) and AcceptAllChanges()? I tried the code given as per my requirement as follows MyEntities…
Manish
  • 47
  • 5
0
votes
0 answers

Transaction Scope with Access Database

I am using Access Database with c# windows application. My application uses different methods to update different tables of database. I want to make my code block transactional but access do not support TransactionScope. Is there any other way of…
SiD
  • 511
  • 4
  • 15
0
votes
2 answers

TransactionScope doesn't roll back while the nth insertion doesn't occur

I have a problem which make me turn around for 3 days. I'm using transaction scope in this transactioscope I insert say 5 values in 5 tables. The insertion goes correctly for the first 3 tables and totally ignore the 4th insertion and insert the 5th…
0
votes
2 answers

EnterpriseLibrary, EF, and Transaction Scope: why am I seeing different behavior?

I have one app that uses EnterpriseLibrary and Unity, and uses TransactionScope in just one place. This works nicely, despite the fact that it runs against SQL Server 2005: // Execute a stored proc using a DbDatabase object inserted by…
Ann L.
  • 13,760
  • 5
  • 35
  • 66
0
votes
1 answer

TransactionScope timing out connection on dev virtualbox VM

I have some code thus: private static void Delete(int PaxID) { using (SqlConnection conn = DataHelper.GetDBConnection()) { using (SqlCommand cmd = DataHelper.GetSPCommand("spDeletePax",conn)) { …
nat
  • 2,185
  • 5
  • 32
  • 64
0
votes
2 answers

TransactionScope yields System.Transactions.TransactionException

I have a database class with methods as shown below. Both foo and bar are all-or-nothing operations. Hence the need for transactions. Note that I'm using MySQL 5.5.21 together with MySQL .NET Connector 6.6.4. public void foo() { using (var…
l33t
  • 18,692
  • 16
  • 103
  • 180
0
votes
1 answer

DataContext.Submit and TransactionScope

Please explain me pseudocode below. My idea is: 3-nd SubmitChanges will commit o.Status and will not commit o.TransactionId, and my object will get corrupted in database (I mean it will not be consistent anymore). XDataContext DB = .....; XOrder o…
Denis
  • 3,653
  • 4
  • 30
  • 43
0
votes
1 answer

DTS transaction fails: Can not access a disposed object

We are running distributed transactions, and on some rare occasions we get the following error: System.ObjectDisposedException: Cannot access a disposed object. Object name: 'SqlDelegatedTransaction'. at …
Marius
  • 9,208
  • 8
  • 50
  • 73
0
votes
1 answer

TransactionScope not working correctly with 2 layer database setup

I have a single method that reaches out to 2 methods. One handles Inserts and the other handles Updates. I put a transaction scope around these 2 methods so if there is any issues it will roll back. I notice that it is putting the data in the…
Tony
  • 3,269
  • 1
  • 27
  • 48
0
votes
2 answers

Update selected rows within transaction

I have an automation project having a remote database (MsSql) and multiple windows/web clients. Client applications check and select a suitable row on a table and mark it as reserved for operating on that row. How can I easily get value and update…
aliassce
  • 1,197
  • 6
  • 19
0
votes
2 answers

subsonic 3 - The operation is not valid for the state of the transaction

I'm trying the following code UserDetail ud = UserDetail.SingleOrDefault(u => u.UserName == CurrentUserName); if (ud == null) ud = new UserDetail(); Address uAddress = ud.AddressId.HasValue ? Address.SingleOrNew(a => a.Id…
freddoo
  • 6,770
  • 2
  • 29
  • 39
0
votes
1 answer

Entity Framework, SqlCommand and TransactionScope

I have a repository done in EF 4.3 Code First (EF) , and another repository that uses regular SqlCommand (SQLCMD). EF pass the connection object to SQLCMD, so both are using the same connection. In EF I create an entity, and use the entity Id to do…
0
votes
1 answer

Using transactions with EF4.1 and SQL 2012 - why is DTC required?

I've been doing a lot of reading on this one, and some of the documentation doesn't seem to relate to reality. Some of the potential causes would be appropriate here, however they're only related to 2008 or earlier. I define a transaction scope. I…
hitch
  • 899
  • 1
  • 11
  • 26
0
votes
0 answers

Nested TransactionScope Exception

The code below throws the following exception. What am I doing wrong? Error Stack: System.Transactions.TransactionAbortedException: The transaction has aborted. ---> System.Data.SqlClient.SqlException: The transaction operation cannot be performed…
niju
  • 117
  • 1
  • 8
0
votes
2 answers

TransactionScope related practice

Can I do any other things (not related to DataBase) in the TransactionScope ? Will it be a bad practice ? e.g Starting a workflow inside the scope. I don't want to save in DB unless starting the workflow fails. If it's a bad practice, what would be…
kevin
  • 13,559
  • 30
  • 79
  • 104