I have just introduced a TransactionScope use to an MVC3 app using EF 4.3 Code First, against a SQL 2010 Express local DB. When I try a SaveChanges inside the scope, I get a "Provider failed to open" notice, with an inner exception about a missing MSDTC. As far as I know, this should only occur if I used multiple connection strings. I only ever use connections to the one DB, I only have 1 string in the app. I do however use several DbContext instances, but only one across the transaction scope.
What can I do about resolving this?
Is MSDTC required? MSDTC is not required for Sql Server installation or operation. If you are only going to use Database Engine, then it is not required or used. If your Sql uses any of the above mentioned query techniques (Linked Server, OPENQUERY, etc), or SSIS or Workstation Components then MSDTC is required.
The Microsoft Distributed Transaction Coordinator (MSDTC) service is a component of modern versions of Microsoft Windows that is responsible for coordinating transactions that span multiple resource managers, such as databases, message queues, and file systems.
not sure if it's similar to this post? How to run two Entity Framework Contexts inside TransactionScope without MSDTC?
workarounds are:
0) Creating Promotable Transactions (depends on SQL server version?) (http://msdn.microsoft.com/en-us/library/ms172070.aspx)
1)Entity Framework – MSDTC Gotchya (http://joeknowsdotnet.wordpress.com/2012/07/19/entity-framework-msdtc-gotchya/)
2) Avoid unwanted Escalation to Distributed Transactions (http://petermeinl.wordpress.com/2011/03/13/avoiding-unwanted-escalation-to-distributed-transactions/)
The first time your application makes a call to EF it will do the initialization (it will build the db if it doesn't exist etc.) If this first call is inside a TransactionScope it will promote to DTC.
To fix this, make a call to EF in your app startup method and this will ensure that EF will be initialized outside of the TransactionScope. From here on in you can include one or more calls to EF inside a TransactionScope and it won't promote to DTC providing: a) You always use EXACTLY the same connection string, and b) You are using Sql Server 2008 and above (which you are).
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