出现以下错误
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.
当我尝试执行以下操作时
using (DataOneContext context1 = new DataOneContext())
{
code...
using (DataTwoContext context2 = new DataTwoContext())
{
more code...
}
}
当我将它们分开时,代码就可以工作了。但是为了让事情变得简单,一个人融入另一个人会更容易。可能吗?
我想避免启用 MSDTC。
DataOneContext 和 DataTwoContext 是 DBML 文件中的表(抱歉,我不知道这个技术术语)。
每个上下文都连接到不同的服务器。
最佳答案
我想你可以通过共享连接来做到这一点(假设是同一个服务器)。当事务使用不同的连接时,它们会自动提升为分布式事务。
using (DataOneContext context1 = new DataOneContext())
{
code...
using (DataTwoContext context2 = new DataTwoContext(context1.Connection))
{
more code....
}
}
关于C# 使用 block 上下文,在另一个使用 block 上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7367006/