当前问题是CS更新数据库,同事更新两台服务器上的两个数据库里的数据。(insert、update)
sqlHandler.ExecuteSqlTran(listCI) 事务A,访问A服务器的a数据库表
sqlCard.ExecuteSqlTran(listCI_Card) 事务B,访问B服务器b数据库表
现在想要将两个事务放在一个事务里,有没有好的方法呢?
用过TransactionScope,报错了,可能我理解的不深,好像是不能访问两个不同的服务器?
想这么做,不过出错了
using (TransactionScope ts = new TransactionScope())
{
int sqlhandler = sqlHandler.ExecuteSqlTran(listCI);
int sqlcardcoupons = sqlCardCoupons.ExecuteSqlTran(listCI_Card); //这里connection.open()的时候就报错了。EX在下面
if (sqlhandler > 0 && sqlcardcoupons > 0)
{
//do others
ts.Complete();
}
}
服务器的DTC服务确认开启了。
EX:([code=csharp]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.
分布事务管理的网络接入(MSDTC)已被禁用。请启用DTC使用组件服务管理工具中配置MSDTC安全网络访问。
)