Distributed Transaction Coordinator

痞子三分冷 提交于 2019-12-18 18:23:23

问题


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#



来源:https://stackoverflow.com/questions/796416/distributed-transaction-coordinator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!