I am trying a very simple distributed transaction on Windows 10 PC, but MSDTC.exe keeps dying every time I run the code.
I am new to MSDTC, so I've googled to how to set it up. I've configured everything for it from giving authorization to Network Service (User) to the folders that are related to MSDTC (dlls involved with it, app running the distributed transaction, etc.),
and disabled firewalls. But I still get errors as shown below.
Error messages:
-0x8004D01B: ("XACT_E_TMNOTAVAILABLE", "The transaction manager is not available."),
-0x8004D01D: ("XACT_E_CONNECTION_DENIED", "A request to establish a connection with the transaction manager was denied."),
-from the Event Viewer
The XA Transaction Manager attempted to load the XA resource manager DLL.
The call to LOADLIBRARY for the XA resource manager DLL failed:
DLL=C:\Users\swx\Desktop\dll,
HR=0x8007007e, File=com\complus\dtc\dtc\xatm\src\xarmconn.cpp Line=2503.
I thought maybe you can do msdtc only on Window servers, but that doesn't make sense to me b/c clients should be able to run distributed actions on their PCs as well. I'd love anyone's input and help, because this problem has been frustrating me beyond limits for over a week now. Below is a C# code I am using to test msdtc.
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
}
}
}
}