ASP » ObjectContext » SetAbort

Syntax:
ObjectContext.SetAbort

The SetAbort method declares that a transaction has not been completed and resources should not be updated.

The SetAbort method explicity declares that a transaction has not been completed and prevents resources from being updated.

If it exists, the OnTransactionAbort event is processed.

Examples

Code:
------------------------File1.asp-------------------
<HTML>
<HEAD>
</HEAD>
<BODY>
<form action="File2.asp" method="POST">
ProductID:<input type="Text" name="ProductID">
Product Name:<input type="Text" name="Name">
Quantity Wanted:<input type="Text" name="Order">
<input type="Submit" name="Submit" value="Submit">
</form>
</BODY>
</HTML>
 
------------------------File2.asp-------------------
<%
@Transaction = "Required"
set connDB=server.createobject("adodb.connection")
connDB.Open "products", "", ""
productID = Request.Form("ProductID")
mySQL="Select * from products Where productID = " & productID
Set rsProductSrch = Server.CreateObject("ADODB.Recordset")
rsProductSrch.Open mySQL, connDB, adOpenStatic, adLockPessimistic
If rsProductSrch.BOF Or rsProductSrch.EOF Then
    ObjectContext.SetAbort
ElseIf rsProductSrch.Fields("Quanity") < Request.Form("Order") Then
    Response.Write "There is not enough in stock to give the present order. There are " & rsProductSrch.Fields("Quanity") & "in stock and your order is for " & Request.Form("Order") & ".<br>"
    ObjectContext.SetAbort
Else
    rsProductSrch.Fields("Quanity") = rsProductSrch.Fields("Quanity") -
            Request.Form("Order")
    rsProductSrch.Update
    ObjectContext.SetComplete
End If
rsProductSrch.Close
connDB.Close
%>
 
Sub OnTransactionAborted()
Response.Write "The transaction aborted because there was not enough quantity on hand to fill your order."
End Sub
 
Sub OnTransactionCommit()
Response.Write "The transaction was committed and your order is being sent."
End Sub
Output:
The transaction aborted because there was not enough quantity on hand to fill your order.