transactionscope

Simpleroleprovider causing remote transaction inside transactionscope

时光毁灭记忆、已成空白 提交于 2019-12-13 04:24:15
问题 I am in the process of upgrading asp.net membership to the new simplemembership provider in MVC4. This is an Azure/Sql Azure app which runs fine on localhost but fails when deployed. I have code in a transaction as follows: TransactionOptions toptions = new TransactionOptions(); toptions.IsolationLevel = System.Transactions.IsolationLevel.Serializable; using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, toptions)) { try { ... do a bunch of database stuff in a

Volatile IEnlistmentNotification and TransactionScope.AsyncFlowEnabled = true

拜拜、爱过 提交于 2019-12-12 17:23:22
问题 Apart from .NET 4.5.1 there is a new option on the TransactionScope which enables to use async flow. This allows to write the following client code using(var txt = new TransactionScope(..., TransactionScopeAsyncFlowOption.Enabled) { await sender.SendAsync(); } So far so good. But when I need to implement a volatile IEnlistmentNotification I'm struggling to do that. Let's imagine the following scenario, assumption: My underlying infrastructure is completely async from bottom to top public

How to create nested transactions in Entity Framework using TransactionScope?

强颜欢笑 提交于 2019-12-12 13:08:33
问题 I know EF 6 DbContextTransaction, but I'm getting bad experience with it over nested transaction. Now I'm trying solely using TransactionScope for nested transaction, but also having problem. This code involved 3 tables changes. When an exception occured in inner trx dbTrx2, it messed up dbTrx1, as dataChg3.SaveChanges() will failed. using (var dbTrx1 = new System.Transactions.TransactionScope()) { ... dataChg1..... foreach(var dataChg2 in listOfDataChg2) { ... try { using (var dbTrx2 = new

TransactionScope locking table and IsolationLevel

六眼飞鱼酱① 提交于 2019-12-12 10:43:02
问题 I want to use TransactionScope in my project. I read about it and I found that it creates an implicit transaction in the database. I want to know if that TransactionScope locks tables that it manipulates? For example in this code: using (Entities ent = new Entities()) { using (TransactionScope tran = Common.GetTransactionScope()) { var oldRecords = ent.tblUser.Where(o => o.UserID == UserID); foreach (var item in oldRecords) { ent.tblUser.DeleteObject(item); } and public static

SqlConnection and TransactionScope Timeout

こ雲淡風輕ζ 提交于 2019-12-12 10:25:03
问题 I have a TransactionScope (over DTC, read committed) with a timeout of 60 minutes. In the TransactionScope I have opened the connection (I hope to enlist in the transaction) but after 30 seconds I get a timeout. In the machine.config I changed the system.transaction maxTimeout to 60 minutes. Why does the timeout occur after 30 seconds? 回答1: A SqlCommand already has a CommandTimeout property that defaults to 30 seconds. May be you are using it within your transaction. 来源: https://stackoverflow

Entity Framework Transaction With Multiple Threads

北城余情 提交于 2019-12-12 08:38:30
问题 I have an application running multiple threads. The threads do NOT share an ObjectContext (each thread has its own - I know they are not thread safe). However, the threads are all operating under a shared Transaction. The original thread creates a TransactionScope and each thread it spawns creates a TransactionScope using a DependentTransaction from the Transaction on the main thread. When multiple ObjectContext requests run at the same time, I sometimes (not consistently) get the error:

TransactionScope and method call that uses the same connection

末鹿安然 提交于 2019-12-12 05:37:28
问题 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 Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool. So this is the pseudo-code: public static void Method1() { using

.NET TransactionScopes and SQL 2005 Lightweight Transaction Manager - Multiple Connections same SPID?

泄露秘密 提交于 2019-12-12 01:35:00
问题 Can someone shed light on what is happening behind the scenes with the SQL Lightweight transaction manager when multiple connections are opened to the same DB, using the Microsoft Data Access Application Block (DAAB)? With the below code, we verified that MSDTC is indeed not required when opening 'multiple connections' to the same database. This was the first scenario I tested: (where Txn1 and Txn2 use EntLib 4.1 to open a connection to the same DB and call different SPROCS) using (var ts =

Retrieve the maximum IDENTITY id using transactionscope

霸气de小男生 提交于 2019-12-12 00:56:50
问题 Here is the code: using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { DBContext.AddtoSomeTable(record); System.Threading.Thread.Sleep(5000); DBContext.SaveChanges(); MAX_ID = (from t in DBContext.SomeTable select t.ID).Max(); scope.Complete(); } As far as I know, before the scope is completed, the MAX_ID should be the new record's ID, which is just inserted. Even if there are two users submitting at the same time, the later one should wait until the

Single threaded object rollback in C#

和自甴很熟 提交于 2019-12-11 21:14:41
问题 In this question Transactions for C# objects? user nicolas2008 posted the code which is able to do rollback to changed object. I paste the code below. I would like to ask is that code safe to use or do you see some dangers in that? Also how it compares to Memento pattern? public sealed class ObjectTransaction : IDisposable { bool m_isDisposed; Dictionary<object, object> sourceObjRefHolder; object m_backup; object m_original; public ObjectTransaction(object obj) { sourceObjRefHolder = new