1
votes
  1. Is there anyway to find if a DbContext is enlisted in any transaction while enlist=false in the connection string? I was tracing DbContext.Database.CurrentTransaction, but I noticed it is always null.

  2. I know when enlist=false, all opened connections will not enlist themselves in an ambient transaction, is that right?

  3. If (2) is correct, how to enlist DbContext in an transaction where TransactionScope is used?
  4. Finally, I noticed using clones of DependentTransaction with multiple DbContext and multiple threads while enlist=false will not promote the transaction to distributed one, but I wonder am I still able to commit and rollback in case an exception happened using the dependent transaction while enlist=false?
  5. if (4) is incorrect, then is there any way to fully avoid DistributedTransaction while being able to open multiple connections with a single transaction scope?

FYI, currently Oracle database is employed; however, in future MySQL is going to be in operation as well.

Thank you

1

1 Answers

0
votes

I cant really say something to 1 , 2 and 3.. But:

  1. The distribution-thing is not absolutely clear to me. But however, MS escalates Transactions from LTM (Lightweigt Transaction Manger) to DTC if a some criteria come to play. For Example if you try to access different databases in one transaction..

  2. The escalation from LTM to DTC or the decission if an escalation will be forced is a system-decission. Until now I didnt find a way to change this behaviour. Thats why you need to think about the transactions in general. If there is a possibility to avoid multiple-database access you may rethink your transactions.

For further information I´ll recommend Why is my TransactionScope trying to use MSDTC when used in an EF Code First app? , MSSQL Error 'The underlying provider failed on Open' and How do I use TransactionScope in C#?