为什么我的交易没有升级为DTC? [英] Why isn't my transaction escalating to DTC?

查看:59
本文介绍了为什么我的交易没有升级为DTC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的机器上禁用了D​​TC.我的理解是该代码应该失败,因为它在同一事务中使用两个数据上下文.那么,为什么行得通呢? (注意:我使用.NET 3.5和.NET 4.0进行了尝试.)

DTC is disabled on my machine. It is my understanding that this code should fail, because it uses two data contexts in the same transaction. So, why does it work? (Note: I tried this using .NET 3.5 and .NET 4.0.)

using (TransactionScope transactionScope = new TransactionScope())
{
    UpdateEta();
    UpdateBin();

    transactionScope.Complete();
}

以下是被调用的DAL方法:

Here are the DAL methods that get called:

public static void UpdateBin(Bin updatedBin)
{
    using (DevProdDataDataContext dataContext = new DevProdDataDataContext(ConnectionString))
    {
        BinRecord binRecord = (from bin in dataContext.BinRecords
                               where bin.BinID == updatedBin.BinId
                               select bin).FirstOrDefault();

        binRecord.BinID   = updatedBin.BinId;
        binRecord.BinName = updatedBin.BinName;

        dataContext.SubmitChanges();
    }
}  

public static void UpdateEta(Eta updatedEta)
{
    using (DevProdDataDataContext dataContext = new DevProdDataDataContext(ConnectionString))
    {
        EtaRecord etaRecord = (from eta in dataContext.EtaRecords
                               where eta.ID == updatedEta.ID
                               select eta).FirstOrDefault();

        etaRecord.ID    = updatedEta.ID;
        etaRecord.Title = updatedEta.Title;

        dataContext.SubmitChanges();
    }
}

推荐答案

两者之间的连接字符串是否不同?如果不是,可能是它们都从相同的基础连接池中重用了相同的连接,从而消除了升级为DTC的需要?

Are the connection strings different between the two? If not, it might be that they both reuse the same connection out of the same underlying connection pool, eliminating the need to promote to DTC?

这篇关于为什么我的交易没有升级为DTC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆