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

Workflow Foundation and DTC transaction Rollback misbehavior

I'm testing the receive transaction scope in workflow foundation 4.5 and i think that there's something wrong with it! See when I roolback a transaction either by explicit roolback: using (TransactionScope s = new TransactionScope()) { using…
Leonardo
  • 10,737
  • 10
  • 62
  • 155
0
votes
1 answer

Entity Framework TransactionScope not rolling back

I've got a Publication table and a Receipt table. When I publish data out, I track it in the Publication table. When my test client receives that publication back from the broker, I track it in the Receipt table. My Publication table has a…
Langdon
  • 19,875
  • 18
  • 88
  • 107
0
votes
1 answer

Nested TransactionScope Rollback - Is it possible?

I am trying to wrap two TransactionScopes within another TransactionScope, but when I run the program and an error is triggered in the 2nd transaction scope, the 1st transaction is not rolled back. Is it possible to rollback both, or am I better off…
0
votes
1 answer

execute two different methods of ActiveRecords in one transactions

Is there any possible way to define a transaction for active record methods? I have Two activeRecords named as Answer and QuizMark which have tow method.I want say server to execute them as a trasaction. here is my code : public function…
hamedkh
  • 909
  • 3
  • 18
  • 35
0
votes
1 answer

linq2sql transactionscope timeout

I have added a transactionscope to a function that every night clears some tables and add the new items. The problem that I get the following error: Inner exception: Transaction Timeout The transaction has aborted. The job takes about 12 minutes to…
0
votes
2 answers

TSQL Scope with table variable

I have a list of tables, some of which have column Employee_ID. At least one table is missing at least one Employee_ID. I want to find Employee_ID's missing from other tables. I run the following, but get a, "Must declare scalar variable," error…
0
votes
2 answers

TransactionScope doesn't rollback on exception CSLA 4.3

I have a BO (Country) with a child BO (State) which also has a child BO (City). When I update the parent BO (Country), add a child State and run save, when an exception occurs in the DAL (on purpose), the transaction is not rolled back. I am using…
Mensur
  • 1,196
  • 3
  • 18
  • 30
0
votes
1 answer

What is the difference between nesting a Transaction with the default Required option, and not doing it all?

I've seen examples of code where a TransactionScope is nested inside another like this using(TransactionScope scope1 = new TransactionScope()) { try { //Start of non-transactional section using(TransactionScope scope2…
happygilmore
  • 3,008
  • 4
  • 23
  • 37
0
votes
4 answers

Can TransactionScope be used across 2 databases on the same Microsoft SQL server?

I have a situation where when I update user I also have to keep track of all changes made to the user - sort of like activity log for the user table. This activity log is located in a different database on the same DB server. But when I wrap these 2…
Marko
  • 12,543
  • 10
  • 48
  • 58
0
votes
1 answer

NHibernate with ASHX and TransactionScope

Have a IHttpModule setup to open and close, begin and commit NH isession and transaction etc. Have a piece of code in a ASHX handler similar to this, that is called by some ajax: using (var transactionScope = new TransactionScope(...)) { // Do…
TheITGuy
  • 722
  • 4
  • 15
0
votes
1 answer

Is it possible to step outside of the current TransactionScope and insert data

Consider the following: using (var outerScope = new TransactionScope()) { InsertDataInTableOne(); InsertDataInTableTwo(); InsertDataInTableThree(); outerScope.Complete(); } Now I want to have InsertDataInTableOne to be run outside…
Peter
  • 13,733
  • 11
  • 75
  • 122
0
votes
2 answers

Flowing transaction to Workflow Foundation 4.5

i have this very simple workflow: As you all can see it consist of a receive a simple assign and a sendresponse, all in a receive transaction scope. Now on the consumer side i have this simple piece of code: static void Main(string[] args) …
Leonardo
  • 10,737
  • 10
  • 62
  • 155
0
votes
2 answers

Need For a TransactionScope Which Won't Rollback With An Exception

I have Some Command Like Insert, Update, Create and so on that i want to run them in some database in a SQL instance. i use transaction scope for this and i want to run all of the commands on all databases even if some errors occurred. if some…
Farzad Karimi
  • 770
  • 1
  • 12
  • 31
0
votes
1 answer

optimal isolation level for specific applications

Trying to understand isolation levels better - using entity framework and sql server What would be the recommended isolation level for the following scenario - An online booking system say for flight tickets or event tickets Scenario - Let us…
0
votes
1 answer

Transactional operations simultaneously mixed with non-transactional ones

I need to perform data import from external source to my database. Because there is a lot of data to download, the import is executing for a long time and I need to persist periodic updates about current importing state to the database (for the user…
jwaliszko
  • 16,942
  • 22
  • 92
  • 158