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();
}
}
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With