【发布时间】:2014-10-17 20:54:58
【问题描述】:
我有类似这样的代码的功能:
using(var db = new MyDbContext())
{
//a whole bunch of code, db is working.
//then I try opening another DbContext like so
using(var dba = new AnotherDbContext())
{
//about 2 lines of code just to get something from a database
}
}
然后当我到达第二个 DbContext 时收到 2 条错误消息:
“底层提供程序在打开时失败。” &“服务器 'myserver' 上的 MSDTC 不可用。”
有人知道发生这种情况的原因吗?我可以一次打开 2 个 DbContext 吗?
【问题讨论】:
-
嗯,在一个方法中混合两个上下文/数据库/任何东西在一般编程中通常是一个非常糟糕的主意。为什么你需要这样做?到目前为止听起来像是一个糟糕的建筑设计......
-
我使用一个数据库来存储我可以在所有项目中使用的 CanadaPost 信息。 @walther