C # Distributed transactions and MSDTC

Source: Internet
Author: User
# 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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.