多台服务器和一个数据库的 WCF 分布式事务
有两台服务器正在WCF上运行一些服务。 所有服务都使用共享数据库。 所有服务都使用带有允许事务流的传输 net.tcp
我们开始使用 TransactionScope 后出现问题: 第一种方法成功创建用户 第二个方法成功获取了他的个人资料
,但第三个方法失败,并出现错误,在数据库中找不到用户
using(TransactionScope scope = new TransactionScope())
{
long employeeId = serviceOnServerA.CreateEmployee(profile);
var employeeProfile = serviceOnServerA.GetEmployeeProfile(employeeId );
serviceOnServerB.CreateContract(employeeId);
scope.Complete();
}
,但这种情况:
using(TransactionScope scope = new TransactionScope())
{
long employeeId = serviceOnServerA.CreateEmployee(work1);
var employeeProfile = serviceOnServerA.GetEmployeeProfile(employeeId );
scope.Complete();
}
serviceOnServerB.CreateContract(employeeId);
工作正常,但不适合我的任务;
问题是在服务器A上创建的本地事务在服务器B上不可见。 有人知道如何解决这个问题;
There are two servers are running some services on WCF.
All services are working with a shared database.
All services use transport net.tcp with allowed transaction flows
Problem appeared after we start use TransactionScope:
The first method successfully creates the user
second successfully gets his profile
but the third method fails with error user not found in database
using(TransactionScope scope = new TransactionScope())
{
long employeeId = serviceOnServerA.CreateEmployee(profile);
var employeeProfile = serviceOnServerA.GetEmployeeProfile(employeeId );
serviceOnServerB.CreateContract(employeeId);
scope.Complete();
}
but such scenario:
using(TransactionScope scope = new TransactionScope())
{
long employeeId = serviceOnServerA.CreateEmployee(work1);
var employeeProfile = serviceOnServerA.GetEmployeeProfile(employeeId );
scope.Complete();
}
serviceOnServerB.CreateContract(employeeId);
Work fine, but not suitable for my task;
The problem is seen that the local transaction created on the server A is not visible on server B.
Somebody known how to solve this problem;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题解决了。问题与使用的 npgsql 数据库提供程序相关,该提供程序不支持 DTC。
代码重写为 MSSQL - 问题就消失了。
The problem solved. Problem related with used npgsql database provider, which not supported DTC.
Code rewrited to MSSQL - and problem gone.