Which error mode to use when executing an ADO transaction in classic ASP?

I am performing a database transaction using ADO and VBScript on a classic ASP page that involves multiple calls to the Execute method of the connection object (i.e. conn.Execute ). I found that I need to set "On Error Resume Next" at the top of my page so that when any of the transaction calls (ie Conn.Execute) fail, I can execute it with a return code. Is it possible to execute an ADO transaction even though my classic ASP page has "On Error GoTo 0" and not "On Error Resume Next" enabled? Sample code to return a transaction looks like this.

'Rollback transaction if a previous conn.Execute fails
if err.Number <> 0 then
    if tranCount = 1 then
       tranCount = 0
    end if
end if



source to share

1 answer

Interest Ask! I usually don't do database transactions from classic ASP, so I'm not sure if conn.Errors will catch errors before ASP-script. But you can at least try ...

IF conn.Errors.Count > 0 THEN
    response.write "whoops"


Otherwise, it might help you know that On Error Resume Next is only valid in the current scope. (see code below)

    response.write "start"
    response.write "middle"  '//<--- This will be printed

    dim b : b = 8 / 0  '//Division by zero

    response.write "end"    '//<-- This will NOT be printed!

    Function BadFunction()
        On Error Resume Next
        dim a : a = 9 / 0  '//Division by zero

        BadFunction = a
    End function





All Articles