When to do an ADO rollback

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Colin Steadman

    When to do an ADO rollback

    While scouting around this group, I've stumbled upon this ASP script
    which deals with rolling back transactions -

    '-- Error Handler
    if oConn.Errors.Co unt > 0 then
    oConn.RollbackT rans
    Response.Write( "FAIL")
    Response.End
    Response.write( err.description )
    end if


    Which has given me pause to wonder if what I am doing is correct. I'm
    basing my rollback on the err.number not being 0 (sample code below).
    Is this ok, or should I be using the conn.errors.cou nt property
    instead?

    TIA,

    Colin


    If Not UpdateDealerPeo pleInfoPending Then
    conn.RollbackTr ans
    response.redire ct("msg_employm ent_status_upda te.asp?error=2" )
    End If

    Function UpdateDealerAct ionsSummited()

    On Error Resume Next

    sql = "random sql update statement"
    conn.execute sql, , &H00000080
    Set sql = Nothing

    'Errors?
    If err.number <> 0 Then
    UpdateDealerAct ionsSummited = False
    Else
    UpdateDealerAct ionsSummited = True
    End If

    End Function
  • Aaron Bertrand [MVP]

    #2
    Re: When to do an ADO rollback

    > Response.End[color=blue]
    > Response.write( err.description )[/color]

    This response.write will never happen.
    [color=blue]
    > Which has given me pause to wonder if what I am doing is correct. I'm
    > basing my rollback on the err.number not being 0 (sample code below).
    > Is this ok, or should I be using the conn.errors.cou nt property
    > instead?[/color]

    Well, the err.number could be <> 0 for simple warnings that can't be
    suppressed (e.g. if your procedure does an sp_rename). So in some cases,
    this isn't enough...

    However, if you are using SQL Server, it would be much more reliable to
    handle your error errors and transactions within a stored procedure.





    Comment

    Working...