Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't my transaction escalating to DTC?

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();
    }
}
like image 468
Bob Horn Avatar asked May 06 '11 16:05

Bob Horn


2 Answers

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?

like image 142
CodingWithSpike Avatar answered Oct 25 '22 07:10

CodingWithSpike


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.

like image 27
Pete Stensønes Avatar answered Oct 25 '22 07:10

Pete Stensønes