|
MTS Transactions
A transaction is an operation or set of operations that succeeds or fails as a logical unit. A good example of a transaction is the transfer of funds from one bank account to another. In this case, the funds must be debited from the first account and credited to the second account before the operation can be considered a success. If the funds are successfully debited but not credited, the debit from the first account must be undone to leave both accounts in a correct and consistent state. Transactions are normally managed by declaring boundaries around a set of operations. Operations that execute in the context of the transaction boundary then succeed or fail as a unit. For ASP.NET, the transaction boundary is the execution of a single request to a page, which might contain nested components that participate in the same transaction. While the page is executing, if an operation on the page itself or a nested component in the same transaction fails, it can call ContextUtil.SetAbort. This is then picked up by the current transaction context, the entire transaction fails, and any operations that were already completed are undone. If nothing fails, the transaction is committed. ASP.NET support for transactions consists of the ability to allow pages to participate in ongoing Microsoft .NET Framework transactions. Transaction support is exposed via an @Transaction directive that indicates the desired level of support:
<%@ Transaction="Required" %> The following table defines the supported transaction attributes. The absence of a transaction directive is the same as an explicit directive to "Disabled". Unlike ASP, ASP.NET has no explicit directive for none (that is, Transaction="None").
A transaction can be explicitly committed or aborted using static methods of the System.EnterpriseServices.ContextUtil class. You can explicitly call the SetComplete or SetAbort method to commit or abort an ongoing transaction. Note: A transaction will commit or abort at the end of page's lifetime depending on whether the SetComplete or SetAbort was called last, provided there is no other object joining the same transaction.
' Try to do something crucial to transaction completing.
If (Not DoSomeWork())
ContextUtil.SetAbort()
End If
VB
Section Summary
|