简体   繁体   English

可以在单个TransactionScope中使用多个Entity Framework数据上下文吗?

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

I'm attempting to use multiple EntityFramework 6 DataContexts in a TransactionScope using{}. 我正在尝试使用{}在TransactionScope中使用多个EntityFramework 6 DataContext。

I get the following Exception 我得到以下异常

A first chance exception of type 'System.Data.Entity.Core.EntityException' occurred in mscorlib.dll mscorlib.dll中发生类型为'System.Data.Entity.Core.EntityException'的第一次机会异常

Additional information: The underlying provider failed on Open. 附加信息:基础提供程序在打开时失败。

Inner Exception 1 内部异常1

Network access for Distributed Transaction Manager (MSDTC) has been disabled. 分布式事务管理器(MSDTC)的网络访问已被禁用。

Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool. 请使用组件服务管理工具在MSDTC的安全配置中为网络访问启用DTC。

Inner Exception 2 内部例外2

The transaction manager has disabled its support for remote/network transactions. 事务管理器已禁用对远程/网络事务的支持。

(Exception from HRESULT: 0x8004D024) (来自HRESULT的异常:0x8004D024)

The code works fine without the TransactionScope. 该代码可以在没有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? 我究竟做错了什么?

It's not EF that's stopping you, but DTC. 不是EF阻止了您,而是DTC。 DTC is needed when using two or more simultaneous connections to MSSQL. 当使用两个或多个同时连接到MSSQL时,需要DTC。

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

ps. PS。 Duplicate of MSDTC issue with transactions in ADO.NET Entity Framework MSDTC问题与ADO.NET实体框架中的事务重复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM