为什么在EF Code First应用程序中使用我的TransactionScope时尝试使用MSDTC? [英] Why is my TransactionScope trying to use MSDTC when used in an EF Code First app?

查看:121
本文介绍了为什么在EF Code First应用程序中使用我的TransactionScope时尝试使用MSDTC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚针对SQL 2010 Express本地数据库向使用EF 4.3 Code First的MVC3应用程序引入了TransactionScope用法。当我在合并范围内尝试SaveChanges时,我收到提供程序无法打开的通知,但内部缺少有关MSDTC的异常。据我所知,仅当我使用多个连接字符串时,才应该发生这种情况。我只使用到一个数据库的连接,应用程序中只有1个字符串。但是,我确实使用了多个DbContext实例,但是在整个事务范围内只使用了一个实例。

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.

如何解决这个问题?

推荐答案

不确定是否与此帖子相似?
如何在没有MSDTC的情况下在TransactionScope内运行两个实体框架上下文?

not sure if it's similar to this post? How to run two Entity Framework Contexts inside TransactionScope without MSDTC?

解决方法是:

0)创建可升级的事务(取决于SQL Server版本?)( http://msdn.microsoft .com / en-us / library / ms172070.aspx

0) Creating Promotable Transactions (depends on SQL server version?) (http://msdn.microsoft.com/en-us/library/ms172070.aspx)

1)实体框架– MSDTC Gotchya( http://joeknowsdotnet.wordpress.com/2012/07/19/entity-framework-msdtc-gotchya /

1)Entity Framework – MSDTC Gotchya (http://joeknowsdotnet.wordpress.com/2012/07/19/entity-framework-msdtc-gotchya/)

2)避免不必要地升级到分布式事务( http://petermeinl.word press.com/2011/03/13/avoiding-unwanted-escalation-to-distributed-transactions/

2) Avoid unwanted Escalation to Distributed Transactions (http://petermeinl.wordpress.com/2011/03/13/avoiding-unwanted-escalation-to-distributed-transactions/)

这篇关于为什么在EF Code First应用程序中使用我的TransactionScope时尝试使用MSDTC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆