# Distributed transactions and MSDTC. This is the problem that is addressed here:
# Distributed Transactions and MSDTC
This is the problem that is addressed here:
If a request needs to perform multiple actions:
{
int Iget=methoda ();
if (iget>0) {
MethodB ();
}
}
There are two methods available:
int MethodA () {}
BOOL MethodB () {}
It is possible that a execution succeeds, but B is unsuccessful and needs to be rolled back, which requires both the system transaction of MSDTC and the distributed transaction.
Its main function is to make the code block a transactional code, under the System.Transactions namespace. Use the following methods:
using (TransactionScope scope = new TransactionScope ())
{
try{
int Iget=methoda ();
if (iget>0) {
MethodB ();
}
}finally{
//
}
Scope.complete ();
}
Note that there is a need for very little code, in which execution of the complete method of the scope executes a commit of the transaction, and if any exception is thrown, the transaction rolls back.
If a distributed transaction cannot run when multiple computers are running, confirm the following:
1: Assurance management Tools-"component management-" Component Services-"computer-" My Computer, right click Properties, MSDTC, all tick, how to control, something.
2: To ensure that two computers can ping each other, note that ping bios Name, with the Netstat-n command, and then C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOST
The inside is written for example:
192.168.1.15 s
That's when Ping S is 192.168.1.15 this computer.
3: Microsoft provides a special tool called dtcping, can test the state of PRC, the same testing MSDTC.