Can multiple Entity Framework Data Contexts be used within a single TransactionScope?

2

I'm attempting to use multiple EntityFramework 6 DataContexts in a TransactionScope using{}.

I get the following Exception

A first chance exception of type 'System.Data.Entity.Core.EntityException' occurred in mscorlib.dll

Additional information: The underlying provider failed on Open.

Inner Exception 1

Network access for Distributed Transaction Manager (MSDTC) has been disabled.

Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool.

Inner Exception 2

The transaction manager has disabled its support for remote/network transactions.

(Exception from HRESULT: 0x8004D024)

The code works fine without the TransactionScope.

Here are the questions I need answered:

What is the best way to apply transactions to two datacontexts being used at the same time? What am I doing wrong?

c#
.net
entity-framework
transactionscope
asked on Stack Overflow Dec 14, 2013 by Chris • edited Jun 20, 2020 by Community

1 Answer

1

It's not EF that's stopping you, but DTC. DTC is needed when using two or more simultaneous connections to MSSQL.

See http://msdn.microsoft.com/en-us/library/dd327979.aspx

ps. Duplicate of MSDTC issue with transactions in ADO.NET Entity Framework

answered on Stack Overflow Dec 14, 2013 by Will • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0