我正在Windows 10 PC上尝试一个非常简单的分布式事务,但是每次运行代码时,MSDTC.exe都会死掉。我已经为它配置了所有内容,从授予网络服务(用户)授权到与MSDTC相关的文件夹(与之相关的dll,运行分布式事务的应用程序等)以及禁用的防火墙。我已经在Google搜索了3天,找不到治愈方法。能否请你帮忙?谢谢!
class Program
{
static void Main(string[] args)
{
string connstr = "this str works for non-distributed transactions";
PerformTransaction(connstr);
}
private static void PerformTransaction(string connstr)
{
bool first_tx_result = false;
bool second_tx_result = false;
try
{
using (TransactionScope ts = new TransactionScope())
{
using (OleDbConnection con = new OleDbConnection(connstr))
{
con.Open();
using (OleDbCommand cmd = con.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = string.Format("INSERT INTO T84073 ( NO, NAME, SAL) VALUES (3000, 'king', 1000)");
cmd.ExecuteNonQuery();
first_tx_result = cmd.ExecuteNonQuery() == 1;
}
// throw new Exception("Transaction not working out");
using (OleDbCommand cmd = con.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = string.Format("INSERT INTO T84073 ( NO, NAME, SAL) VALUES (3000, 'ksdg', 1000)");
cmd.ExecuteNonQuery();
second_tx_result = cmd.ExecuteNonQuery() == 1;
}
if (first_tx_result && second_tx_result)
{
ts.Complete();
}
}
}
}
catch
{
//rolling back is taken care of by transaction scope
}
}
}
}
错误消息: -0x8004D01B :(“ XACT_E_TMNOTAVAILABLE”,“交易管理器不可用。”)
-0x8004D01D :(“ XACT_E_CONNECTION_DENIED”,“与事务管理器建立连接的请求被拒绝。”),
-从事件查看器 XA事务管理器尝试加载XA资源管理器DLL。 XA资源管理器DLL对LOADLIBRARY的调用失败: DLL = C:\ Users \ swx \ Desktop \ dll, HR = 0x8007007e,File = com \ complus \ dtc \ dtc \ xatm \ src \ xarmconn.cpp Line = 2503。