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

Sqlclient transaction and .Commit()

In this code will the SomeFunction() after the .commit() be considered part of the transaction? Would it rollback if something blew up? I need to do further processing after dynamic records are inserted and would prefer to do it all in one big…
Somejerk
  • 193
  • 1
  • 11
0
votes
1 answer

C# System.Transaction.RollBack

** EDIT: Okay , thanks for the anser. so what is the purposeof transactions if it isnt use for SQL? This article show an example of using simple transactions: http://msdn.microsoft.com/en-us/library/ms172152(v=vs.90).aspx what is the purpose of…
Stav Alfi
  • 13,139
  • 23
  • 99
  • 171
0
votes
1 answer

Multiple TransactionScope - fetches outdated information

This post is somewhat related to this post of mine: How to synchronize database access in a WCF Service? The responses I got there were over-complicated and \ or contradicting ... :( I have created a sample WCF service, and I run 3 instances of…
John Miner
  • 893
  • 1
  • 15
  • 32
-1
votes
0 answers

How TransactionScope works under the hood

I just found out TransactionScope() class in c#. I get what it does, but I do not get how ado.net commands detect that they are executing inside transaction scope ? Also, I wonder how can I detect that my code is under TransactionScope. using…
user19291301
  • 127
  • 8
-1
votes
1 answer

"The transaction has aborted" getting caught even when intentionally aborting

A bit of context on how I'm using TransactionScope, as of currently in the program if any of the three databases' queries catches an error, I made it so that the TransactionScope will dispose everything which results in none of the data getting…
-1
votes
1 answer

Structure SQL insert Transactions for C# Parent / Child objects

I'm developing some business-ware objects in C#. Each object has the ability to save itself to a associated database like such (each object): public void Save() { //Collect object attributes and convert to SQLParameters //Add SQL Parameters…
samwich
  • 37
  • 6
-1
votes
1 answer

C# - TransactionScope outside of a using block?

The query I have is a little more complex than the title lets on. Perhaps this is a foolish question, but I couldn't find any certain answer when searching online. Currently, I'm implementing the Repository/Unit-of-Work pattern in my own flavor and…
-1
votes
1 answer

link server SQL transaction scope not working

I am not able to use the connection within the transactionscope It is displaying the error MSDTC on "server" is unavailable.
-1
votes
3 answers

TransactionScope and method call that uses the same connection

I'm using TransactionScope to make a method that contains multiple sql statements transactional. Now i need to call a second method that also uses the same connection and i receive following exception at connection.Open(): Network access for…
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
-1
votes
5 answers

Transaction Scope for local database

I'm currently trying to implement some End to End Tests (E2E) using TranactionScope and local file Database (mdf). funny is that the query is not being rolled back, so all my update/inserts are persisted. I dont understand what is done wrong …
Roman Kern
  • 11
  • 2
-1
votes
1 answer

TransactionScope fails check constraint

I am having a issue using TransactionScope and a check constraint in SQL Server. I want to insert into the table as such: Col A | Col B ------------ Dave | 0 Fred | 1 The table has a check constraint that there must always be an entry in Col B…
DasDave
  • 801
  • 1
  • 9
  • 28
-2
votes
1 answer

C# TransactionScope does not rollback when I stop the debugger

I have this simple code working fine in runtime in my Controller, ASP Net 4.6 and SQL Server 2014, but when run in debug mode (step by step) and I stop de process in the middle of transaction scope, the changes in database are committed. How can it…
Jorge
  • 1
  • 1
-2
votes
1 answer

C# TransctionScope implementation on multiple forms

I have situation in which I need to insert a record to the DB from one form (Form1) and then open another form (Form2) in which I have to add more details to the DB and when return back to Form1. Finally, I have to open another form (Form3) from…
-2
votes
1 answer

In Java: How to rollback when update Active Directory or database fail?

In Java, I have 2 methods to do: Update some attribute data in the AD. Update some data in the field in the table. If item 1 or Item 2 fail system must be rollback. I want to do which if both items updated complete then commit the process. If one…
1 2 3
69
70