Automatic transaction and ASP.NET
Insert transaction instructions in the ASP.NET page, you can indicate that the page is involved in existing transactions, starting new transactions or never participates in transactions.
The following table lists and describes the transaction instructions available in ASP.NET.
Disabled indicates that ASP.NET will ignore the transaction context. This is the default transaction status. NotSupported Indicates that the page does not run within the transaction. After processing the request, the object context is created regardless of whether there is an activity transaction. Supported Indicates that the page runs in the context of existing transactions. If there is no transaction, the page is running without transaction. Required This page runs in the context of existing transactions. This page will start a transaction if there is no business. RequiresNew Indicates that page requires transactions and launches new transactions for each request.
<% @ Page Transaction = "Required"%>
Automatic transaction and XML Web Services
be usable
WebMethodaTribute
Attribute class
TransactionOption
Attribute declares an automatic transaction.
[WebMethod (TransactionOption = TransactionOption.RequiresNew)] public int DeleteAuthor (string lastName) {String deleteCmd = "DELETE FROM authors2 where au_lname = '" lastName "'"; SqlConnection sqlConn = new SqlConnection ( "Integrated Security = SSPI; database = Pubs; Server = myserver "); sqlcommand mycommand = new sqlcommand (deletecmd, sqlconn);
Mycommand.connection.open (); return mycommand.executenonquery ();
Vote in automatic transaction
The .NET Framework class and the ASP.NET page can be submitted or suspended by voting or aborted their current transactions. By default, if there is no explicit voting in the code, the default is submitted. However, the default submission may extend the time used to release expensive resources for each transaction, making it possible to reduce the performance of the application. Explicit voting also allows classes or pages to stop business when they encounter serious errors. Use the Auto-Complete System.EnterpriseServices.autocompletettribute to make the transaction to complete the transaction when the object is returned to the method. If the method calls triggers an exception, the transaction is aborted. This feature can only be applied from
ServicedComponent
The class derived. [Transaction (TransactionOption.Supported)] public class Account: ServicedComponent {.. [AutoComplete] public void Debit (int amount) {// Do some database work Any exception thrown here aborts the transaction; // otherwise, transaction commits}} using Setabort and SetComplete can use public setcomplete or setabort method
System.EnterpriseServices.ContextUtil