TransactionScope alternative without DTC

Is there an alternative to a Scope transaction that should not include DTC ??

In a transaction, I need to perform two operations:

  • Create one user (using membership in membership - sql)
  • Do an insert operation.
+4
source share
2 answers

TransactionScope uses LTM, a lightweight transaction manager in .NET. Only if you open several connections in one transaction or switch between databases, TransactionScope advertises a transaction with a 2PC DTC TX manager.

For MS SQL Server 2008 and higher, DTC will be enabled only if you open connections to various databases. OR if you open connections in the same transactions from multiple EXCEPT threads, if you use DependentTransaction , that you must enlist in your global transaction if you want to execute threads.

As a side item: I have multithreaded history support in Castle.Transactions .

Lateral point # 2: If you use TransactionScope, be sure to declare IsolationLevel explicitly, otherwise you will serialize all your transactions (IsolationLevel.Serializable)!

+10
source

Add Enlist=false in the connection string of your membership.

 connectionString="Data Source=xxx;Initial Catalog=xxx;Persist Security Info=True;User ID=xxx;Password=xxx;Enlist=false" 

This is my use case:

 using (TransactionScope tScope = new TransactionScope()) { MembershipCreateStatus createStatus; Membership.CreateUser(model.Email, model.Password, model.Email, null, null, true, model.Id, out createStatus); if (createStatus == MembershipCreateStatus.Success) { Roles.AddUserToRole(model.Email, "Administrator"); _UpdatePersonnelAccess(model); _UpdatePersonnelHasAccess(model); _SendEmail_Welcome(model); PersonSessionLog.ManageSession(model); } else ViewBag.Message = "Error"; tScope.Complete(); } 

My application is published on Amazon EC2, and the database is on Amazon RDS. DTC is not supported in RDS, so I also need a way to prevent the DTC from escalating. By the way, I am using SQL Server 2008 R2. I have 2 databases - ASPNETDB, data DB

Thanks Paul post !

+1
source

All Articles