-->

Distributed Transaction Coordinator

2019-02-11 07:51发布

问题:

I am trying make a database transaction(inserting records) across multiple system. So, I decided to use System.Transaction Namespace in .net. I configured MSDTC on both system(But i dont know whether i configured correctly). My transaction has two insert query one will execute at local system. another, will execute at some other system in a local network. First insert query work successfully but second one raise a error like : Message = "The transaction has already been implicitly or explicitly committed or aborted."

Please help in this case to over come.


Here is my Code

    using (TransactionScope txSc = new TransactionScope())
    {
        //vrm = new VolatileRM();
        //vrm.SetMemberValue(3);
        try
        {
            using (SqlConnection cn = new SqlConnection(connStr1))
            {
                SqlCommand cmd = cn.CreateCommand();
                cmd.CommandText = "Insert into empdetail Values ('YYY')";
                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();
            }
            using (SqlConnection cn = new SqlConnection(connStr))
            {
                SqlCommand cmd = cn.CreateCommand();
                cmd.CommandText = "Insert into stu Values ('23','senthil')";
                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();
            }                    
            txSc.Complete();
        }
        catch (Exception e)
        {
            txSc.Dispose();
        }

    }

回答1:

First check that the DTC is actually running (on local and remote system), and then try setting both DTC's authentication to 'anonymous' to see if it's a permissions problem.

Also, check the firewall settings on remote and local machine.

Check out this FAQ: Distributed Transaction Coordinator(MSDTC) and Transaction FAQ

Configuring MS DTC Services

  • Enable Network Access Securely for MS DTC
  • Enable Firewall Exceptions for MS DTC

Related to this SO question: HRESULT: 0x8004D00E using TransactionScope - C#



标签: msdtc