开发者

C# Using block context, within another using block context

开发者 https://www.devze.com 2023-04-04 01:17 出处:网络
I get the following error Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security

I get the following error

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.

When I try to do the following

using (DataOneContext context1 = new DataOneContext())
{
     code...

     using (DataTwoContext context2 = new DataTwoContext())
     {
          more code...
     }
}

When I separate them, the code works. But to have things simple, it'd be easier for one to be in the other. Is it possible?

I would like to avoid enabling MSDTC.

DataOneContext and DataTwoContext are the tables in the DBML file (sorry I don't know the technical term).

Each context is conne开发者_如何学运维cting to a different server.


I think you can do this by sharing the connection (assuming the same server). Transactions automatically get promoted to distributed transactions when they use different connections.

using (DataOneContext context1 = new DataOneContext()) 
{ 
     code... 

     using (DataTwoContext context2 = new DataTwoContext(context1.Connection)) 
     { 
         more code....
     } 
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消