. NET Distributed Transaction Processing

Source: Internet
Author: User

 

Transactions are often used for data persistence. Generally, ADO. the transaction processing in. NET can meet our needs, but, ADO.. NET transactions cannot be atomic operations performed by colleagues on multiple database connections. If multiple databases or file writes exist in your business environment, you can also consider using it to ensure data integrity and consistency.. NET distributed transaction processing.

The use of Distributed Transaction processing requires support from the Windows system. Therefore, we need to enable the system's MSDTC Service. Steps: Management Tools> component services; expand Console Root Node> component services> Computer> my computer; right-click my computer to open "properties "; on the tab, select "use local coordinator" and click "OK", as shown in:

After the configuration is complete, we can easily use distributed transaction processing. First, add "System. Transactions" reference to the project, and then write the following code:

{
{
TransactionOptions transactionOption. Timeout
{
Action. Invoke ();
Scope. Complete ();
}
}
}

 

The above code is the core code for executing the transaction. You only need to run the code as a delegate to pass in the InvokAction and enter a timeout value. At the end of the transaction execution, you can call the Complete method to submit the transaction. If the Complete method is not called, no commit is performed even if the transaction execution is Complete. If an exception occurs, all code will not change.

----------------------------------------------------------

Ps:

1. A problem is also found. The database also needs to enable support for distributed transactions: Right-click the "server connection" attribute, select "connection" in the Open Properties window, and on the right of the window, select "you need to use distributed transactions for server-to-server communication" and click OK.

2.20.specify the distribution port number, which is the exception of msdtc.exe under.

3. Cross-origin scenarios need to be studied.

4. In a transaction, even if nested data exists, all database connections in the same transaction are accessible to the data.

5. In a transaction, if you use the Response. Redirect () method to jump to another page, the transaction will not be committed!

Related Article

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.