View Full Version : Ending an ASP script
brendon99
04-07-2004, 03:50 AM
Hi,
I've got an ASP script which is doing database calls. What I want to do is check if there is an error after each execution, and to end the script if it finds one.
What I've coded follows this logic:
Call db statement 1
ErrorCheck()
Call db statement 2
ErrorCheck()
Call db statement 3
ErrorCheck()
ErrorCheck() is a function I created - if it detects an error, it writes out a line in the log file, then "Reponse.end" - but it doesn't.
If I put the "response.end" in the main script, it stops execution fine. Does this mean I have to repeat the same code after each db statement call (instead of the function)? this seems a bit of a waste?
thanks for any help you can provide,
cheers
Brendon99
oracleguy
04-07-2004, 04:33 AM
What about doing something like this?
Call db statement 1
If ErrorCheck()=True then response.end
Call db statement 2
If ErrorCheck()=True then response.end
Call db statement 3
If ErrorCheck()=True then response.end
function errorcheck()
... do your stuff
if err then errorcheck=true
end function
I haven't actually tried this but I think it should work. Do you see what I'm getting at?
brendon99
04-07-2004, 06:20 AM
Yeah, I thought this might be the go, however I just wanted to see if I could reduce the coding somehow.....
thanks anyway
ghell
04-07-2004, 09:20 AM
Yeah, I thought this might be the go, however I just wanted to see if I could reduce the coding somehow.....
thanks anyway
err, isnt that what you asked for? seems like it to me. its still using a function but it returns a value which u check, instead of copying the contents of the function every time.. whats wrong with that?
brendon99
04-08-2004, 03:06 AM
Well mostly I just wanted to understand why I could response.flush the contents of the ASP page through a sub/function call, but why response.end wouldn't work through a sub/function call?
glenngv
04-12-2004, 05:46 AM
response.end anywhere should work. Can you post the code?
brendon99
04-13-2004, 06:25 AM
Hi,
here is the sub code for the error check. I would call this immediately after issuing a db command. It writes out an error to the error log, but processing continues regardless.
I'm probably missing something straightforward, since ASP isn't my native language ;)
'----------------------------------------------------------------------
' Error checking
Sub ErrorCheck()
Dim iErrNumber, sErrDesc, sDate, sTime
iErrNumber = Err.number
sErrDesc = Err.description
If iErrNumber <> 0 Then
dim objErrFile, fv_date, fv_time
sDate = date
sTime = time
Set objErrFile = objFileSys.OpenTextFile(constErrorLog, ForAppending, True)
objErrFile.WriteLine(sDate & " " & sTime & " " & iErrNumber & " " & sErrDesc & " User:" & sUserName)
objErrFile.Close
objErrFile = Nothing
DisplayUpdate(" Synchronisation Failed!!")
Response.Write " Error " & iErrNumber & " " & sErrDesc
Response.Write " Click here to <a href='http://replink/AnError.html'> continue</a>"
Response.Write " <script type='text/javascript'>{parent.document.title='An Error occurred...'}</script> "
Response.End
End If
End Sub
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.