Use of transactionscop transaction mechanism

Source: Internet
Author: User

If the transactionscope class (Distributed Transaction) is used in C #, note the following:
1. Reference The using system. Transactions namespace in the project (you must first Add a reference to the net component );

2. Example:

/// <Summary> /// send the message /// </Summary> /// <Param name = "senduserid"> </param> /// <Param name = "touser"> Format: 7ffa3af2-e74b-4154-8403-5010c53e49a7 | username, 7ffa3af2-e74b-4154-8403-5010c53e49a7 | username </param> /// <Param name = "content"> </param> /// <Param name = "sendedstatus"> indicates that the message is sent </param>/ // <returns> </returns> Public static int sendmessage (string senduserid, string touser, string content, string sendedstatus) {int receivecount = 0; transactionoptions transactionoption = new transactionoptions (); // sets the transaction isolation level transactionoption. isolationlevel = system. transactions. isolationlevel. readcommitted; // set the transaction timeout to 60 seconds transactionoption. timeout = new timespan (0, 0, 60); Using (transactionscope scope = new transactionscope (transactionscopeoption. required, transactionoption) {try {// here implement transactional work // send the message insertmessage (senduserid, touser, content, sendedstatus ); // Insert the record receivecount + = insertreceivemessage (userids [0], senduserid, content, "0") in the receiving information table; // No error occurs and the transaction scope is committed. complete ();} catch (exception ex) {Throw new exception ("sending information exception, cause:" + ex. message);} finally {// release the resource scope. dispose () ;}} return receivecount ;}

3. MSDTC component settings:
On the Control Panel ---> Administrative Tools ---> service, enable the Distributed Transaction Coordinator service.
A. Control Panel-> Administrative Tools-> component services-> Computer-> my computer-> right-click-> Properties
B. Select the MSDTC page and confirm "use local coordinator"
C. Click the "Security Configuration" button below
D. Select "allow network DTC Access", "allow remote clients", "Allow inbound", "Allow outbound", and "do not require authentication ".
E. For the database server, you can select "require verification to the caller"
F. Select "enable transaction Internet Protocol (TIP) transaction ".
G.add the msdtc.exe exception to the double fire wall
Command line available: netsh firewall set allowedprogram % WINDIR % \ system32 \ msdtc.exe MSDTC enable

4. Restart the IIS server.

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.