transactionscope

TransactionScope - The underlying provider failed on EnlistTransaction. MSDTC being aborted

一笑奈何 提交于 2019-12-03 11:42:21
Our team have got a problem that manifests as: The underlying provider failed on EnlistTransaction; Cannot access a disposed object.Object name: 'Transaction'. which seemed to appear as soon as we began using TransactionScope to handle our applications' transactions. The top part of the stacktrace is captured as: at System.Data.EntityClient.EntityConnection.EnlistTransaction(Transaction transaction) at System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectContext.ExecuteStoreCommand(String commandText, Object[] parameters) at Reconciliation.Models.BillLines

TransactionScope alternative without DTC

那年仲夏 提交于 2019-12-03 07:36:35
are there any alternative to transactionScope which does not need to enable DTC?? In the transaction I need to make two operations: Create one user (using membership - sql membership provider) Do one insert operation. TransactionScope uses the LTM - Lightweight Transaction Manager in .Net. Only if you open more than one connection in the same transaction or go between databases, should TransactionScope promote the transaction to the 2PC-based TX-manager, DTC. For MS SQL Server 2008 and above, the DTC will become involved only if you are opening connections to different DBs. OR if you are

How to know if the code is inside TransactionScope?

别说谁变了你拦得住时间么 提交于 2019-12-03 07:32:51
问题 What is the best way to know if the code block is inside TransactionScope? Is Transaction.Current a realiable way to do it or there are any subtleties? Is it possible to access internal ContextData.CurrentData.CurrentScope (in System.Transactions) with reflection? If yes, how? 回答1: Transaction.Current should be reliable; I've just checked, at this works fine with suppressed transactions, too: Console.WriteLine(Transaction.Current != null); // false using (TransactionScope tran = new

Ignore TransactionScope for specific query

断了今生、忘了曾经 提交于 2019-12-03 05:39:59
问题 I'm looking for a way to execute a query while a TransactionScope is alive, and ignore the TransactionScope - basically, I want to execute this particular query no matter what. I'm using EF code-first, and the way the application is designed, a new data context is opened many times throughout a single call, each with its own changes, and all of those are contained within a single TransactionScope, which has Complete() called at the end assuming no failures. Inside of the context we've

How to support async methods in a TransactionScope with Microsoft.Bcl.Async in .NET 4.0?

二次信任 提交于 2019-12-03 05:36:12
I have a method similar to: public async Task SaveItemsAsync(IEnumerable<MyItem> items) { using (var ts = new TransactionScope()) { foreach (var item in items) { await _repository.SaveItemAsync(item); } await _repository.DoSomethingElse(); ts.Complete(); } } This of course has issues because TransactionScope doesn't play nice with async/await. It fails with an InvalidOperationException with the message: "A TransactionScope must be disposed on the same thread that it was created." I read about TransactionScopeAsyncFlowOption in this answer , which appears to be exactly what I need. However, for

High volume site using ADO.NET TransactionScope vs ExecuteCommand on NOLOCK, READ UNCOMMITTED directly?

做~自己de王妃 提交于 2019-12-03 00:42:32
Just read this interesting article by Omar on his blog Linq to SQL solve Transaction deadlock and Query timeout problem using uncommitted reads and at the end Javed Hasan started arguing with him about his solution to the nolock situation on a high volume site. Here, the problem trying to solve is, from the sql sense we need to use Select statements with NOLOCK or use SET TRANSACTION LEVEL READ UNCOMMITTED, otherwise at high volume rows in DB will be locked and cause errors. The technology Omar used is Linq2Sql, so the question is how do we get this achieved in your C# data access code so the

Using TransactionScope around a stored procedure with transaction in SQL Server 2014

[亡魂溺海] 提交于 2019-12-02 19:33:53
I am using C# and ADO.Net with a TransactionScope to run a transaction in an ASP.Net app. This transaction is supposed to save some data across multiple tables and then send an email to subscribers. Question : is it a valid use of TransactionScope , when it includes a call to a stored procedure that has its own transaction in SQL Server 2014, or should I remove the SQL transaction statements i.e. begin tran , commit tran and rollback tran statements from the stored procedure being called within this TransactionScope ? The C# code for this scenario and also the T-SQL code of stored procedure

Ignore TransactionScope for specific query

安稳与你 提交于 2019-12-02 18:59:14
I'm looking for a way to execute a query while a TransactionScope is alive, and ignore the TransactionScope - basically, I want to execute this particular query no matter what. I'm using EF code-first, and the way the application is designed, a new data context is opened many times throughout a single call, each with its own changes, and all of those are contained within a single TransactionScope, which has Complete() called at the end assuming no failures. Inside of the context we've overridden SaveChanges so that if any exception happens on base.SaveChanges() , we can catch it and log to the

Passing around a SqlConnection

梦想与她 提交于 2019-12-02 09:59:03
问题 I have created a TransactionScope and within the scope various items are created and updated in the database. During this process I make a lot of calls to the database. Originally I opened a SqlConnection in the beginning of the TransactionScope and passed it around to any function that made a DB call then I closed the connection after all the calls are made and before the transaction commits. Is it better to do this or to open and close a connection (using the same connection string) for

Get current .net TransactionScope IsolationLevel

China☆狼群 提交于 2019-12-02 09:57:10
I have an utility method creating TransactionScope in my application. I want to do a unit test to validate that the returned TransactionScope has the correct IsolationLevel set, to be sure that nobody can modify the code without breaking the tests. System.Transactions.Transaction scope does not have public properties exposing information like that. ( http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx ) Any way to get this information? Can you run a SQL query to check the isolation level: SELECT CASE transaction_isolation_level WHEN 0 THEN 'Unspecified' WHEN 1