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
6
votes
0 answers

.Net Framework Data Provider error 60

I've received the following error from the live site: System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: Internal .Net Framework Data Provider error 60.…
6
votes
0 answers

Using TransactionScope with SQLite causes database locked exception

I am trying to adapt a c# code that uses TransactionScope and works with Oracle to work also with SQLite. My code is structured in a way that every method called within the transaction scope that accesses the SQLite database creates its own…
stambikk
  • 1,175
  • 12
  • 23
6
votes
5 answers

What is the best way to rollback a .net transaction?

This question is related to my question: SQL Server and TransactionScope (with MSDTC): Sporadically can't get connection I'm doing some transaction programming using the .net TransactionScope class. If I understand correctly, I can do some SQL…
Vivian River
  • 31,198
  • 62
  • 198
  • 313
6
votes
1 answer

Entity Framework Forcing Distributed Transaction

I am unable to get the following code that only touches a single database using a single context to run without escalating to MSDTC, and is throwing an exception on context.SaveChanges(): public void DeleteGroupDetails(int groupId) { // Note…
Eric Scherrer
  • 3,328
  • 1
  • 19
  • 34
6
votes
1 answer

How to implement a memory transaction scope in C#?

we have a cache which I would like to put some transaction scopes around so that any process have to explicitly 'commit' the changes it wants to do to the cached objects and make it possible to rollback any changes when the process fails halfway as…
theburningmonk
  • 15,701
  • 14
  • 61
  • 104
6
votes
1 answer

Multiple databases(datacontext) on same server without MS DTC

I'm using EF5.0 with SQL server 2008. I have two databases on the same server instance. I need to update tables on both databases and want them to be same transaction. So I used the TransactionScope. Below is the code - public void Save() { …
Sai
  • 629
  • 1
  • 8
  • 26
6
votes
3 answers

Common Gotchas when using TransactionScope and MS DTC

I am just starting to work with using TransactionScope, I find that there are always unexpected things I run into that take forever to debug. I figure that having a consolidated list of these would be great for those "weird error" circumstances,…
Gord
  • 1,805
  • 3
  • 17
  • 22
6
votes
5 answers

Data committed even though System.Transactions.TransactionScope.Commit() not called

Under what circumstances can code wrapped in a System.Transactions.TransactionScope still commit, even though an exception was thrown and the outermost scope never had commit called? There is a top-level method wrapped in using (var tx = new…
Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220
6
votes
2 answers

Sql transaction failure

I am getting below error while inserting records in database. System.Transactions.TransactionException: The operation is not valid for the state of the transaction. ---> System.TimeoutException: Transaction Timeout --- End of inner exception…
Rajat Saini
  • 557
  • 7
  • 26
6
votes
2 answers

Commit and rollback Oracle transactions

I'm calling this proc in C# from oracle. I made the proc to return an error. In other words the proc fails and pv_error is populated with string and the rollback gets triggered, but doesn't work. I'm not sure why. So, what am I doing wrong? Thanks…
Werner van den Heever
  • 745
  • 6
  • 17
  • 40
6
votes
2 answers

TransactionScope alternative without DTC

are there any alternative to transactionScope which does not need to enable DTC?? In the transaction I need to make two operations: Create one user (using membership - sql membership provider) Do one insert operation.
Pedre
  • 446
  • 1
  • 8
  • 16
6
votes
1 answer

Preparing for multiple EF contexts on a unit of work - TransactionScope

I'm thinking of the options in regards to implementing a single unit of work for dealing with multiple datasources - Entity framework. I came up with a tentative approach - for now dealing with a single context - but it apparently isn't a good…
5
votes
1 answer

How does a TransactionScope implementation work? What database support is required?

Just reading up on TransactionScope implementations. Could someone confirm if this technique is driven by client-side .net, or if it requires something special from specific DB Vendors? Is this a SQL Server only thing?
sgtz
  • 8,849
  • 9
  • 51
  • 91
5
votes
1 answer

Nested TransactionScope and/or nested connections causing MSDTC escalation

I am trying to avoid MSDTC escalation in my application. I am using LINQ with SQL Server Express 2008 R2, and later will be using the full version. I have written a database wrapper class which creates connections as necessary and disposes of them…
enashnash
  • 1,578
  • 1
  • 15
  • 36
5
votes
1 answer

Turning off Transactions in Entity Framework

We're trying to implement a quick prototype to prove something is possible with the Entity Framework... We have an Informix DB that doesn't support transactions - is it possible to use the Entity Framework with this? We have a working model, and the…
Stuart.Sklinar
  • 3,683
  • 4
  • 35
  • 89