Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  Loops: Timeouts #2
     [next Lesson]  Server Variables: Popular Ones

Do Loop Intercept Timeouts by Charles Carroll

The transactional nature of ASP pages can be used to intercept a script timeout.

loop3.asp traps a timeout:
   filename=/learn/test/loop3.asp

<Test Script Below>


<%@ TRANSACTION=Required%>
<%
response.buffer=true
server.scripttimeout=10
%>
<HTML>
<TITLE>loop3.asp</TITLE>
<body bgcolor="#FFFFFF">
<head><meta name="Robots" content="Noindex,Nofollow" /></head>
</BODY>
<%
DO UNTIL COUNTER = 111111
    counter=counter+1
    response.write counter & "<br>"
    iFlush = iflush + 1
    if iflush = 25 then
          iflush = 0
          Response.Flush
    end if
LOOP
'response.flush
response.write "Script executed without incident"
%>
</HTML>
<%
Sub OnTransactionAbort()
    response.clear
     Response.Write "The Script Timed Out"
end sub
%>

loop4.asp succeeds and does not trigger the trap:
   filename=/learn/test/loop4.asp

<Test Script Below>


<%@ TRANSACTION=Required%>
<%
response.buffer=true
server.scripttimeout=40
%>
<HTML>
<TITLE>loop4.asp</TITLE>
<body bgcolor="#FFFFFF">
</BODY>
<%
DO UNTIL counter=400
    counter=counter+1
    response.write counter & "<br>"
LOOP
response.flush
response.write "Script Exexuted without incident!"
%>
</HTML>
<%
Sub OnTransactionAbort()
    response.clear
     Response.Write "The Script Timed Out"
end sub
%>
Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site