Elastic transactions with MS SQL Server

1

Considering the following code snippet:

using (var scope = new TransactionScope())
{
    using (var conn1 = new SqlConnection(connStrDb1))
    {
        conn1.Open();
        SqlCommand cmd1 = conn1.CreateCommand();
        cmd1.CommandText = string.Format("insert into T1 values(1)");
        cmd1.ExecuteNonQuery();
    }

    using (var conn2 = new SqlConnection(connStrDb2))
    {
        conn2.Open();
        var cmd2 = conn2.CreateCommand();
        cmd2.CommandText = string.Format("insert into T2 values(2)");
        cmd2.ExecuteNonQuery();
    }

    scope.Complete();
}

Source

When trying to run it locally in my application with .NET Framework 4.5, an exception is thrown showing the need to enable the MSTDC service.

  

System.Data.Entity.Core.EntityException: The underlying provider   failed on Open. --- >   System.Transactions.TransactionManagerCommunicationException: Access   to the Distributed Transaction Manager (MSDTC) network was   disabled. Enable DTC network access in the configuration of   of the MSDTC using the   Components.


In this article it became clear to me that in scenarios of platform-as-a-service applications in Azure for example, MSDTC is not available, and the ability to coordinate distributed transactions has been integrated into the database, thus creating the concept of elastic transactions . But such a feature would only be available from the .NET Framework 4.6.1 or later.

I upgraded my application to the .NET Framework 4.7.2, but when I tried to run the same locally code snippet , I still had the same error.

  

In fact, it is only possible to perform distributed transactions (using   only my MS SQL Server server and disregarding the   Azure) enabling the MSTDC service? Is there any way to implement   something like elastic transactions without the need for MSTDC?

I'm using MS SQL Server 2016.

    
asked by anonymous 13.06.2018 / 15:53

0 answers