Elastic transactions with MS SQL Server

Asked

Viewed 70 times

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 generated 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 disabled. Enable DTC network access in DTC configuration MSDTC security using Administrative Services tool Components.


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

I upgraded my application to . NET Framework 4.7.2, but while trying to run the same code snippet locally, I still made the same mistake.

Rereading the article already cited, in the section that talks about the limitations, I understood that such resource is only available if the application is using the Azure database.

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

I am using MS SQL Server 2016.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.