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
8
votes
2 answers

Dtcping test passes but still have a Communication with the underlying transaction manager has failed

DTCPing tool says everything should be fine. The actual exception is: System.Transactions.TransactionManagerCommunicationException: Communication with the underlying transaction manager has failed. ---> …
Kimi
  • 13,621
  • 9
  • 55
  • 84
8
votes
3 answers

.NET Transactionscope options

I am a newbie in C#. So i was just wondering if anybody can help me figure out how C# works with transactionscope? Because i am a little confused by the definition of it. However, let me explain about my problem a little bit. So that you will get to…
Mystic
  • 81
  • 1
  • 3
8
votes
3 answers

2 sibling nested transactionScope gives: the Transaction has aborted

this code gives me the error: the Transaction has aborted. if I remove 1 nested transaction than it doesn't throw using(var scope = new TransactionScope()) { repo.Insert(new Foo {Fname = "aaaa"}); using(var s = new…
Omu
  • 69,856
  • 92
  • 277
  • 407
8
votes
1 answer

Is it possible to create a TransactionScope in a Custom WCF Service Behavior? (async, await, TransactionScopeAsyncFlowOption.Enabled)

TL;DR ? Screencast explaining problem: https://youtu.be/B-Q3T5KpiYk Problem When flowing a transaction from a client to a service Transaction.Current becomes null after awaiting a service to service call. Unless of course you create a new…
Ajden Towfeek
  • 387
  • 2
  • 14
8
votes
1 answer

TransactionScope locking table and IsolationLevel

I want to use TransactionScope in my project. I read about it and I found that it creates an implicit transaction in the database. I want to know if that TransactionScope locks tables that it manipulates? For example in this code: using (Entities…
Arian
  • 12,793
  • 66
  • 176
  • 300
8
votes
2 answers

TransactionScope and SQLite database gets locked

I am trying to use Entity Framework 6 with SQLite and running into a database locked issue when trying to use TransactionScope. Here is my code: using (var txn = new TransactionScope()) { using (var ctx = new CalibreContext()) { var…
Mensur
  • 1,196
  • 3
  • 18
  • 30
8
votes
3 answers

What are the good and bad points of TransactionScope?

What are the good and bad points of the TransactionScope class in C#? Thanks.
hovkar
  • 1,381
  • 3
  • 14
  • 22
8
votes
2 answers

TransactionScope helper that exhausts connection pool without fail - help?

A while back I asked a question about TransactionScope escalating to MSDTC when I wasn't expecting it to. (Previous question) What it boiled down to was, in SQL2005, in order to use a TransactionScope, you can only instance and open a single…
Yoopergeek
  • 5,592
  • 3
  • 24
  • 29
8
votes
1 answer

Does EF5 DbContext.SaveChanges handle transaction commit and rollback?

I am not clear on whether I need to use TransactionScope or DbContext.SaveChanges() is enough to commit my transaction consisting of multiple CRUD operations. I am using SQL Server in the backend.
Jas
  • 516
  • 1
  • 6
  • 13
8
votes
2 answers

How can I create safe per-web-request transaction in .net's MVC?

I need to be all my entire application transactional in its every web request it processes. I need the transaction to start and, if there was no exceptions in controllers, commit it. Otherwise, rollback. So far, I have the following…
8
votes
2 answers

Using TransactionScope when integration testing web apis

At the moment, I'm doing something similar to this to integration test a library that communicates with our API controllers, and so far so good, but I've run into a snag. In all of our other integration tests, we run the test inside an MSDTC…
8
votes
1 answer

How can I implement WCF Transaction support on custom class using CoreService?

I wrote a class to assist in adding & removing Destinations to a Publication Target using the Core Service. Destinations are normally exposed as a string (with XML content) via the Core Service, so I wrote my own wrappers around that, etc. I now…
Nuno Linhares
  • 10,214
  • 1
  • 22
  • 42
8
votes
1 answer

Ignore SqlTransaction.Commit within TransactionScope

We are in a process of gradually replacing legacy data access code by entity framework (4.3.1). In some occasions we can't avoid using both ways of data access in one unit of work. Ideally, this should be done in one transaction. However, the old…
Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
7
votes
2 answers

TransactionScope does not rollback inside wcf service method, does roll back if called directly

I am facing a problem that drives me crazy for couple of days now, hoping someone can help me. Here it is ; I'm using EF4 with oracle database, using dotConnect for oracle from devart as provider. I have wcf service method which calls DeleteCabinet…
rayback2
  • 81
  • 5
7
votes
2 answers

Does TransactionScope work with pre-existing connections?

I have a code like this: try { using (TransactionScope scope = new TransactionScope()) { some_db_function(); for (i = 0; i < 10; i++) { some_other_db_function(); } scope.Complete(); …
Siyavash
  • 452
  • 1
  • 5
  • 13