Use of distributed transactions in ASP. NET, transactions

Source: Internet
Author: User
Tags odbc connection

Use of distributed transactions in ASP. NET, transactions

I have previously published a transaction storage process. I recently encountered distributed transactions in my project. I would like to summarize all of them and share some experiences with you. First, why do we need distributed transactions? Let's talk about where I encountered distributed transactions in the project. When I was developing the website background, I usually stored the image path in the database when there was an image table design, images are stored in the folder of the website. Therefore, when we operate the product table, when I want to delete the image path of the database product, I also need to delete the images under the website directory, to achieve this function, I used distributed transactions.


1. The System. Transactions assembly must be referenced in the project.

2. In the code method that requires transaction control: System. Transactions. TransactionScope scop = new System. Transactions. TransactionScope ()

3. You must start the Distributed Transaction Coordinator service to run Distributed transactions normally.

The following is an example of the main code I wrote:

1 // 3. delete the image of the database and folder by id 2 3 // 3.0 get object 4 ProductEntity entity = Product_BLLSub.Get_ProductEntity (int. parse (id); 5 // 3.1 create a transaction 6 using (System. transactions. transactionScope scop = new System. transactions. transactionScope () 7 {8 // 3.2 Delete the data of the database image 9 Product_BLLSub.Create_ProductDelete (int. parse (id); 10 12 // 3.3 get the image path 13 string thumphyPath = context. server. mapPath ("/upload/thum/") + entity. img_url; 14 string imgPhyPath = context. server. mapPath ("/upload/img/") + entity. img_url; 15 // 3.4 Delete the thumbnail 16 if (System. IO. file. exists (thumphyPath) 17 {18 System. IO. file. delete (thumphyPath); 19} 20 // 3.5 Delete the source image 21 if (System. IO. file. exists (imgPhyPath) 22 {23 System. IO. file. delete (imgPhyPath); 24} 25 // 3.6 submit the transaction 26 scop. complete (); 27} 28 35 // 36 Response deleted successfully. write ("deleted successfully ");

Note: My database operation method is to convert the database data to an object, and then operate the database by operating the object.

Error logging in distributed transactions

I. A. Do not use transactions. Use SELECT statements. Can I perform distributed queries?

B. LINKSERVER cannot operate on the local machine when performing distributed update transactions (that is, it cannot return distributed transactions)

C. dbcc traceon (3604,730 0) -- use tracking to view more detailed error information. the dtcping.exe package of msbench on two machines and run it according to README instructions. See error information.

2. Whether MSDTC is enabled for both machines.

Iii. Whether MSDTC is set correctly.
1. Open the command prompt, Run "net stop msdtc", and then run "net start msdtc ".
2. Go to "Component Service Management Tools ".
3. Browse to "start management tool ".
4. Select "component service ".
A. Expand the "component service" tree and then expand "my computer ".
B. Right-click "my computer" and select "properties ".
C. On the MSDTC tab, make sure the following options are selected: Network DTC Access
Network Management
Network transactions
XA transaction
E. In addition, "DTC Logon account" must be set to "NT Authority \ NetworkService ".
5. Click OK ". This will prompt you that "ms dtc will stop and restart.
All dependent services will be stopped. Press "yes" to continue ". Click "yes" to continue.
6. Click "OK" to close the "my computer" Properties window.

MSDTC depends on RPC. RPC uses port 135 to test whether port 135 is enabled. Is there a firewall? If the firewall is disabled first.
Telnet IP 135
If it is disabled, open it.

For various reasons, SQLOLEDB cannot use distributed transactions and is changed to "MSDASQL" ODBC connection.
Use RRAS instead of RAS. (control panel -- Management Tools -- remote service manager)
Check whether you are using Remote Access Server (RAS) to access remote servers. if so, make sure that you have implemented Routing RAS (RRAS ). linked server does not work on RAS because RAS allows only one way communication.

7. Check whether your two servers are in the same domain.
If the remaining full text is...>

Distributed Design of NET

Multi-layer design is not advantageous in small systems
Let's give a simple example.
For example, an energy management system
Its data source has two types of DB2 Oracle
You can switch between interfaces in the middle layer.
Both DB2 and Oracle connections are supported.
Therefore, the middle layer is very important for scalability.
If you want to change both layers
It can only be said that your design may be faulty.
The middle layer is not flexible enough

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: 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.