Transactions in DOTNET and COM + (2)

Source: Internet
Author: User
Tags dotnet


Homepage
One of the new transactions: transactions in DOTNET and COM + (2)
One of the new transactions: transactions in DOTNET and COM +

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

Stingy god

2002-4-16

 

Article type: In-Depth

Difficulty level: 6/9

Version: 2.32

Transaction-related attribute classes in CLR

Attribute Class
Function
 
Autocompleteattribute
The declared transactions are automatically completed in the function.
 
Constructionenabledattribute
Add a construct string
 
Justintimeactivationattribute
Instant Activation
 
Objectpoolingattribute
Object pool
 
Transactionattribute
Declare transactions
 

 

Methods and attributes related to transactions in CLR

Attributes and Methods
Interfaces and Methods
 
Disablecommit
Iobjectcontrol: disablecommit
 
Enablecommit
Iobjectcontrol: enablecommit
 
Setabort
Iobjectcontrol: setabort
 
Setcomplete
Iobjectcontrol: setcomplete
 
Isintransaction
Iobjectcontextinfo: isintransaction
 
Mytransactionvote
Icontextstate: Get/setmytransactionvote
 
Deactivateonreturn
Icontextstate: Get/statedeactivateonreturn
 
Transaction
Iobjectcontextinfo: gettransaction
 
Transactionid
Iobjectcontextinfo: gettransactionid
 
Contextid
Iobjectcontextinfo: getcontextid
 

 

Of course, in the above class, we can also not add any property control, but simply inherit a class from servicedcomponent. When we successfully register our component with COM + with regsvcs, the COM + settings still have some default values, or we use the attributes but do not explicitly specify the attribute values. These are completed by system. enterpriseservices. registrationhelper. In fact, after calling regasm and tlbexp, regsvcs calls it to complete registration on COM + catalogs.

 

The following table lists the attributes of compiled classes in CLR (configured and not configured)

Attribute
Applicability
Value in COM + when no attribute is configured
Use attribute configuration, but the specified attribute value in COM + is not displayed
 
Applicationactivation
Assembly
Library
No Default
 
Applicationid
Assembly
Generated guid
No Default
 
Applicationname
Assembly
Assembly name
No Default
 
AutoComplete
Method
False
True
 
Constructionenabled
Class
False
True
 
Justintimeactivation
Class
False
True
 
Mustruninclientcontext
Class
False
True
 
Objectpooling
Class
False
True
 
Synchronization
Class
False
Synchronizationoption. Required
 
Transaction
Class
False
Transactionoption. Required

Transactionisolationlevel. serializable

Timeout = infinite
 

 

From the above, we can see that attribute programming brings us convenience and simplicity, which is much easier than the COM + programming in the previous com method, it is quite easy to register with the COM + environment without too many references, thread synchronization, or even registration. But it can only be said that if you used to work well under COM, now you can work well or better under CLR, and the COM + and transaction programming models remain unchanged, analyzing and constructing a transaction model from actual needs and applications is still the main task of every developer. But now you can have more time and energy to deal with this problem.

 

 

Configurable transaction isolation level in Windows XP and Windows. net)

 

In the COM + environment of Windows XP and Widnows. net, we can specify the transaction isolation level.

 

This is indeed a long-awaited new feature. In COM + 1.0, we can only use the default and strictest transaction isolation level: serializable. In Windows XP and Windows. net, COM + allows us to specify the transaction isolation level of the component, which can be determined by the developer and the actual application. Not all RM (Resource Management) support the four isolation levels defined currently. One possible policy is to use a higher isolation level when RM does not support the current isolation settings, serializable is the strictest isolation level and the most common isolation level, that is to say, almost all RM support this isolation level setting (the four isolation levels currently supported by COM + are also supported and implemented by ms SQL Server is also the four defined by the SQL-92 ). Not all developers understand the functions and meanings of these options. The following sections provide some common explanations and information to make choices in the future development process.

 

When multiple users operate on the database, data inconsistency may occur. isolation level means that the transaction can accept inconsistent data, which is the degree to which a transaction is isolated from other transactions. Low isolation levels can increase concurrency, but the cost is to reduce data correctness. On the contrary, high isolation levels can ensure data correctness, but may have a negative impact on concurrency. The isolation level required by COM + determines the action of RM using the lock. Different isolation levels may cause different problems, such:

Problem
Description
Instance
 
Dirty read

Dirty read
It is also called uncommitted read or unconfirmed read. A transaction modifies the database but is not submitted or confirmed. At this time, another transaction reads the value and performs the operation.
In the past, James had 1 RMB in his account, a was responsible for deposit, and B was responsible for accounting. Then a first saved 20 RMB but did not submit it. At this time, B read the 20 RMB and then allocated 5 RMB, if a fails to roll back the transaction, B will save 15 yuan to the database to complete the transaction. James is so happy.
 
Repeatable

Nonrepeatable read
It is also called inconsistent read or non-readable. A transaction reads a value. When it reads it again next time, the value changes, but the modification is not dominated by it. It is obviously another transaction operation.
B Learned How To Be smart this time. After obtaining 20 yuan of information for the first time, B First subtracted 5 yuan from his own, and then did not update the database immediately, and checked the database again, the original 20 is now 50. After three seconds, B finds that it is 10, so B is wondering: Isn't I responsible for accounting?
 
Phantom

Phantom
A group of new data is found in two read operations on the same database. The difference between unrepeatable and unrepeatable is that unrepeatable changes or overwrites existing data without adding or decreasing data, phantom inserts or deletes the existing data.
B is sometimes responsible for reporting his latest deposit to James. Although he did not sleep well yesterday, B still makes statistics. He found that at the first statistics, a had 5 Records and 10 records, during the second query and confirmation, it was found that a had added three more pens, eight fewer pens, and nine fewer pens at the beginning of the month. B wanted to take a rest and make statistics again, although it is a bit strange to miss the beginning of the month, if the result is that the total number of A is greater than his own, James still has confidence in his deposit.
 

The following table sets different isolation options to accept concurrency issues. It can be seen that serializable is the strictest and no three possible errors will occur. In order, COM + considers that the isolation values from low to high are small to large, the read uncommitted value is the smallest, And the serializable value is the largest.

Isolation level
Dirty read
Unrepeatable
Phantom occurred
 
Read uncommitted
Yes
Yes
Yes
 
Read committed
No
Yes
Yes
 
Repeatable read
No
No
Yes
 
Serializable
No
No
No
 

 

(Unfinished)

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

Note:

This document is the first release of the csdn signature. for reprinting or adaptation, please indicate the author and source. If you have any questions, please email your new2001@msn.com

The text and images mentioned above involve the privacy and personal rights of others. All texts and images are only used for internal communication and are not used for news or commercial purposes.

 

--------------------------------------------------------------------------------
Copyright? 2005 China. udotnet. com

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.