有两个数据库ds_server_a/catalog_a和ds_server_b/catalog_b,代码如下所示,怎样能够保持db和db2使用同一个transaction呢?求赐教!
var dbFactory = new OrmLiteConnectionFactory(
"Data Source=ds_server_a;Initial Catalog=catalog_a;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False",
SqlServerDialect.Provider);
var otherDbFactory = new OrmLiteConnectionFactory(
"Data Source=ds_server_b;Initial Catalog=catalog_b;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False",
SqlServerDialect.Provider);
try
{
using (IDbConnection db = dbFactory.OpenDbConnection())
{
using (IDbConnection db2 = otherDbFactory.OpenDbConnection())
{
using (IDbTransaction tran = db.OpenTransaction())
{
db.Insert(new BaoLi2136 { Id = 2140, content = "Employee 1" });
db2.Insert(new Bl2136
{
id = 2140,
phone = "123123123",
});
tran.Commit();
}
}
}
}
catch (Exception ee)
{
Console.WriteLine(ee.Message);
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。