Welcome to my blog!

Transaction Scope

June 13, 2021 15:43

Transaction Scope (edit)

Implementing an Implicit Transaction using Transaction Scope | Microsoft Docs

Implementing an Implicit Transaction using Transaction Scope | Microsoft Docs

TransactionScope: A simple way to handle transactions in .NET | Code Wala (2018)

TransactionScope Considered Annoying | Josh the Coder (2020)

  • Transaction Management
  • Transaction or TransactionScope
  • TransactionScope
  • TransactionScope Timeout
  • Multiple databases
  • Dapper
  • Dapper CommandTimeout
  • Logging
  • Autofac DI using in Console Application

All About TransactionScope - CodeProject

Handling Transactions in .NET Using TransactionScope (codeguru.com)

  1. using (var transactionScope = new TransactionScope())
  2. using (var transactionScope = new TransactionScope(TransactionScopeOption.Required)) // default
  3. using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))

c# - Advanced System.Transactions debugging - Stack Overflow

   <source name="System.Transactions" switchValue="Information">
    <add name="tx" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "tx.log" />

[SOLVED] => Transaction scope timeout on 10 minutes (entityframework.net)

Transaction Scope uses the Machine config setting as the maximum timeout. The default machine timeout is 10 minutes.

TransactionScope Has a Default Timeout (stephencleary.com)

Passing TimeSpan.Zero into the TransactionScope constructor will instruct it to use the maximum timeout (TransactionManager.MaximumTimeout, which has a default value of 10 minutes) instead of the default. Unfortunately, the maximum timeout can only be increased by editing the machine.config file.

using new TransactionScope() Considered Harmful | Microsoft Docs

public class TransactionUtils {
    public static TransactionScope CreateTransactionScope() {
        var transactionOptions = new TransactionOptions();
        transactionOptions.IsolationLevel = IsolationLevel.ReadCommitted;
        transactionOptions.Timeout = TransactionManager.MaximumTimeout;
        return new TransactionScope(TransactionScopeOption.Required, transactionOptions);

Show me the code

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions() {
IsolationLevel = System.Transactions.IsolationLevel.Serializable,
Timeout = TimeSpan.FromMinutes(10)

void SomeMethod()
{ try { using (var _transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOptions)) { using (SqlConnection _connection = new SqlConnection(connectionstring)) { _connection.Open(); DoSomething()... } _transactionScope.Complete(); } } catch (TransactionAbortedException e) { nlog.Error(string.Format("The transaction has been aborted: {0}", e.Message)); throw; } catch (Exception e) { throw; } }

Autofac DI container in Console App

dependency injection - Correct use of Autofac in C# console application - Stack Overflow

c# - Autofac DI container in console app - Code Review Stack Exchange

DI in .NET Core Console Application

Dependency injection in .NET Core console applications (gunnarpeipman.com)

TransactionScope & Transaction in EF6

Entity Framework (EF) TransactionScope vs Database.BeginTransaction (vunvulearadu.blogspot.com)

Unit Testing

c# - Full integration test for a Console application - Code Review Stack Exchange

How to unit test C# Dynamics CRM interface code (alexanderdevelopment.net)

jordimontana82/fake-xrm-easy: The testing framework for Dynamics CRM and Dynamics 365 which runs on an In-Memory context and deals with mocks or fakes for you (github.com)


Recent posts