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

Read committed, no locks. Screwed up

I have a weird problem from production systems. I have readCommitted transaction defined with read operation with no_lock and write operation with table lock in the same scope. However, multiple processes are able to override the lock and able to…
Adarsh
  • 203
  • 1
  • 2
  • 6
0
votes
3 answers

SQL server Isolation level

I have n machines writing to DB (sql server) at the exact same time (initiating a transaction). I'm setting the Isolation level to serializable. My understanding is that whichever machine's transaction gets to the DB first, gets executed and the…
Sam
  • 933
  • 5
  • 14
  • 26
0
votes
1 answer

Why does System.Web.Security.Roles.RoleExists in combination with LocalDB source require MSDTC?

In a .NET 4.0 project, I'm experiencing that a call to System.Web.Security.Roles.RoleExists within a System.Transactions.TransactionScope fails due to MSDTC not being enabled on my development machine. The role manager's data source is LocalDB and…
aknuds1
  • 65,625
  • 67
  • 195
  • 317
0
votes
0 answers

Is injecting an argument, in a policy handler, within the unity interception pipeline, permissable?

So I have pulled my transaction scope into an aspect/policy. I want to associate a database connection, just one, with this transaction scope before calling the method (a data access method) in the pipeline which will call one or potentially more…
0
votes
1 answer

Will the page lock be released on committing nested transaction?

It is well known that the database locks taken inside the transaction are released on the end of that transaction. So, in this code.. public static TransactionScope CreateTransactionScope() { return new…
AgentFire
  • 8,944
  • 8
  • 43
  • 90
0
votes
2 answers

Duplicate inserts

I'm having following issue with duplicated inserts in case of concurrent requests. I have two tables: create table tbl ( val varchar2(1000) ); create table tbl2 ( val varchar2(1000) ); I need to insert some value in table tbl2 only in case if…
hades
  • 1,077
  • 3
  • 11
  • 19
0
votes
1 answer

Does TransactionScope makes a cross process lock on the database in LinQ queries?

I got several applications run onto the one machine, also with an MSSQL server on that machine. Applications are various typed, like WPF, WCF Service, MVC App and so on. All of them accessing the only database, which is located on the sql…
AgentFire
  • 8,944
  • 8
  • 43
  • 90
0
votes
1 answer

TransactionScope with Typed Dataset

Is it possible to use TransactionScope with a Typed Dataset? as in: using (var transaction = new TransactionScope()) { typedDataSet.DeleteStuff(id); typedDataSet2.DeleteSomeOtherStuff(id2); transaction.Complete(); } Will the the sql…
marvc1
  • 3,641
  • 3
  • 25
  • 34
0
votes
1 answer

Selecting data from table in one connection from where records are getting deleted/updated in another connection in transaction

We have a ASP.NET web application which sends a request to a windows service to delete/update records in a number of tables. Windows service does this in a stored procedure and that call is in ADO.NET TransactionScope. If number of records involved…
Ashish Gupta
  • 14,869
  • 20
  • 75
  • 134
0
votes
1 answer

Exception handling in transactionscope

This method is called in my business service from an asp.net mvc controller. Should there occur an exception or not I need to return a Result object. The result class is experimental, maybe there is something better. How would you do the exception…
Pascal
  • 12,265
  • 25
  • 103
  • 195
0
votes
1 answer

Entity Framework - Model doesnt update after failed transaction

Working on a project using Entity Framework (4.3.1.0). I'm trying to figure out how to make my code work as a transaction, but for me it seems like my model doesnt update after the transaction has failed. Let me show you: using (TransactionScope…
0
votes
2 answers

Managing transactions between EntityFramework and EnterpriseLibrary's DatabaseFactory

I'm working with an existing set of code that manages multiple database updates in a single transaction. Here is a simplified example: Database db = DatabaseFactory.CreateDatabase(); using (DbConnection dbConnection = db.CreateConnection()) { …
0
votes
2 answers

multiple methods in service of grails

I have created one service in my grails application. in that service 25 methods are there. Some methods are for fetching data and passes to controller and some methods are for applying business logic and others are for database data CRUD…
0
votes
1 answer

Two connections under one Transaction

I searched araound and having some difficulties in implementing one scenario with SQL Server 2000 and sybase. I have two SQL servers on different locations naming ServerA (MSSQL Server) and ServerB (Sybase server). I have a table called…
Tatming
  • 81
  • 1
  • 1
  • 7
0
votes
1 answer

Using Transactions with EntityFramework FROM the business logic layer

Pls see this first: Good Coding Practices So, this is my design. Website 2.Business Logic Layer 3.DALFacade (we use dalfacade to hide the data access, because we use 2 different stores, sql and db2) 4.DAL In the DAL we use unit of work pattern and…
Luis Valencia
  • 32,619
  • 93
  • 286
  • 506
1 2 3
69
70