Transactionscope does not transact

Asked

Viewed 4,965 times

7

I’m trying to use the TransactionScope in C#, I am performing the tests with local bank, but every time I try to execute some method it returns me this Exception:

Partner transaction manager disabled its support for remote/network transactions. (HRESULT exception: 0x8004D025)

I’ve already activated the Distributed transaction coordinator in services and DTC Local in Component Services, without success.

Part of the code:

try
{
    using (var trans = new TransactionScope())
    {
        while (contadorInicial <= contadorFinal)
        {
            Objeto.Codigo = contadorInicial.ToString();
            _objController.Insert(Objeto);
            contadorInicial++;
        }

        trans.Complete();
        return true;
    }
}

1 answer

6


Several steps to enable distributed transaction support:

  1. Administrative Tools > Services
  2. Enable the Coordinator of Distributed Transactions if it is disabled;
  3. Return to Administrative Tools > Component Services;
  4. Go to Component Services > Computers > My Computer > Right click > Properties;
  5. On the tab MSDTC, click on Configurações de Segurança;
  6. Check whether they are checked "DTC Network Access", "Allow Remote Client", "Allow Input/Output Connections", "Enable TIP";
  7. Apply settings and restart your computer.

If it is not necessary to use the TransactionScope necessarily, try the following alternatives:

1. Using Entity Framework

using (var tx = context.BeginTransaction())
{
    while (contadorInicial <= contadorFinal)
    {
        Objeto.Codigo = contadorInicial.ToString();
        _objController.Insert(Objeto);
        contadorInicial++;
    }

    tx.Commit();
}

2. Using Sqlconnection or some derivative

// connection é uma SqlConnection inicializada.
using (var tx = connection.BeginTransaction())
{
    while (contadorInicial <= contadorFinal)
    {
        Objeto.Codigo = contadorInicial.ToString();
        _objController.Insert(Objeto);
        contadorInicial++;
    }

    tx.Commit();
}

Here’s an observation: I don’t know how your DAO works. In any case, it would be nice for your input method to accept a transaction or context as an optional parameter.

  • I have performed all the procedures but the same error keeps occurring, what can I do? (I am trying to perform these procedures on the work computer, and the computers are on a network that is controlled by the IT sector) I wonder if that’s why?

  • Yeah. The database server is on another machine?

  • No, it is a local instance of SQL Server.

  • There is an alternative to Transactionscope that I could use?

  • I’ll put it in the answer.

  • 2

    Thanks, it worked with Sqlconnection!

Show 1 more comment

Browser other questions tagged

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