Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 5th, 2008, 03:33 PM
Authorized User
Join Date: Sep 2004
Location: , , .
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
Default Reloop XMLHTTP.SEND on Error

I am attempting to write something that will try and re-send an xml packet using XMLHTTP when it fails. I often get a timeout or a connection can not be establised when posting to some of our affiliates, so basically if this occurrs I just want to try and repost it 3 times. Here is what I have so far but it is not working...

ON ERROR RESUME NEXT                


if Err.Number <> 0 then

Set ASPErr = Server.GetLastError()
IF AspErr.Number = "-2147012867" then 'a connection could not be established
for x = 1 to 3 'will retry to post 3 times if failed    
    Err.Clear 'clear error to see if raised again
    if Err.Number = 0 then
        parse_continue = true
        Exit For 'exit loop on success
    end if
next x
end if 'end if timeout error

end if 'end if for original error code was not zero
When I run this I get a "Expected end of statement" error, which makes no sense to me considering my loops and if's are all properly closed.

Any ideas?

Old December 5th, 2008, 10:16 PM
Friend of Wrox
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts

Some weird stuff in there.

(1) You are using Server.GetLastError(), but that's only usable on error handling *PAGES* (and, according to IIS docs, even then it's only available to a page that is custome handling a 500;100 ASP error). It has no applicability to errors that you are "trapping" using ON ERROR RESUME NEXT.
(2) You are comparing what you claim to be a number (AspErr.Number) to a *STRING*.
(3) You use ON ERROR RESUME NEXT, but you never *cancel* that, so if (for example) you had a typo in your code 30 or 40 lines after all this code, you would never know it.
(4) You use next x which isn't legal VBScript. (VBScript does NOT allow any variable name after the keyword next.)

Code just seems overly complex to me.

Why not:
parse_continue = False ' assume the worst

For attempt = 1 To 4
   On Error Resume Next ' this automatically does Err.Clear, but go ahead if you are paranoid
       ' why bother doing first attempt outside the loop?
       xmlHttp.Send ping_packet ' the parens here are, strictly speaking, an error
       oops = Err.Number ' Err.Number SHOULD have the cause...not Server.GetLastError
   On Error GoTo 0 ' *ALWAYS* cancel this ASAP!!!
   Select Case oops
       Case 0 
           parse_continue = True
           Exit For
       Case -2147012867  ' see?   compare as a NUMBER
           ' really don't need to do anything, right?
       Case Else
           ' is there any point in continuing if the error isn't one you can handle?
           Exit For
   End Select
Old December 6th, 2008, 03:15 PM
Authorized User
Join Date: Sep 2004
Location: , , .
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post

Terrific - just what I was looking for.

Not sure why I thought I still had to do the server.getlasterror. I appreciate your assistance.

Similar Threads
Thread Thread Starter Forum Replies Last Post
send email error phuc2583 Classic ASP Basics 1 December 16th, 2007 11:22 PM
Permission Denied error on xmlhttp.open call... mussitsch Classic ASP XML 3 October 9th, 2007 02:43 AM
XMLHTTP v3 Automation Error jinyen VB Components 0 May 12th, 2004 03:44 PM
Using XMLHTTP in VBA - Error 400 helentoomik XML 3 July 17th, 2003 04:31 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.