ASP脚本里加事务
事务声明:将某个页声明为事务性,可在页首添加 @TRANSACTION 指令:
<%@ TRANSACTION = value %>
value 参数可以是下列之一:
值 |
意义 |
Requires_New |
启动一个新的事务。 |
Required |
启动一个新的事务。 |
Supported |
不启动事务。 |
Not_Supported |
不启动事务。 |
@TRANSACTION 指令必须在一页中的第一行,否则将产生错误。不要将应用程序的 Global.asa 文件声明为事务性。
事务终止:ObjectContext.SetAbort显式地声明终止一个事务。
事务的响应:使用OnTransactionCommit和OnTransactionAbort事件来编写对用户的不同响应。
<%@ TRANSACTION = Required %>
<%
'Buffer output so that different pages can be displayed.
Response.Buffer = True
%>
<HTML>
<BODY>
<H1>Welcome to the online banking service</H1>
<%
Set BankAction = Server.CreateObject("MyExample.BankComponent")
BankAction.Deposit(Request("AcctNum"))
%>
<P>Thank you. Your transaction is being processed.</P>
</BODY>
</HTML>
<%
' Display this page if the transaction succeeds.
Sub OnTransactionCommit()
Response.Write "<HTML>"
Response.Write "<BODY>"
Response.Write "Thank you. Your account has been credited."
Response.Write "</BODY>"
Response.Write "</HTML>"
Response.Flush()
end sub
%>
<%
' Display this page if the transaction fails.
Sub OnTransactionAbort()
Response.Clear()
Response.Write "<HTML>"
Response.Write "<BODY>"
Response.Write "We are unable to complete your transaction."
Response.Write "</BODY>"
Response.Write "</HTML>"
Response.Flush()
End sub
%>
posted on 2008-06-30 12:45 joyous jeny 阅读(219) 评论(0) 编辑 收藏 举报