分布式事务处理协调器

问题描述 投票:0回答:1

我正在尝试跨多个系统进行数据库事务(插入记录)。因此,我决定在.net中使用System.Transaction命名空间。我在两个系统上都配置了MSDTC(但是我不知道我是否配置正确)。我的事务有两个插入查询,一个将在本地系统执行。另一个将在局域网中的其他系统上执行。第一个插入查询工作成功,但是第二个引发类似以下错误:Message =“该事务已被隐式或显式提交或中止。”


这是我的代码

    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();
        }

    }
msdtc
1个回答
3
投票

首先检查DTC实际正在运行(在本地和远程系统上,然后尝试将DTC的身份验证都设置为'匿名',以查看是否是权限问题。

另外,请检查远程和本地计算机上的防火墙设置。

查看此常见问题解答:Distributed Transaction Coordinator(MSDTC) and Transaction FAQ

Configuring MS DTC Services

与此SO问题相关:HRESULT: 0x8004D00E using TransactionScope - C#

© www.soinside.com 2019 - 2024. All rights reserved.