Why isn't my transaction escalating to DTC?

大城市里の小女人 提交于 2019-12-05 22:02:22

问题


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

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

回答1:


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?




回答2:


I'm not convinced you are using two different contexts from your post.
Besides it was my understanding that if the database connections were to the same database on the same machine then there would be no need to escalate to a DTC. That escalation occurs when two different database servers are used in the transaction.




回答3:


You database connections are not nested. They are sequentially used. Stick one procedure inside the other and try again.



来源:https://stackoverflow.com/questions/5914570/why-isnt-my-transaction-escalating-to-dtc

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