error handling - rolling back changes

Discussion in 'ASP General' started by brendan.wong@gmail.com, Apr 24, 2007.

  1. Guest

    hello. i'm trying to incorporate error handling into my application,
    but i've run into a dilemma.

    i've already performed 10 successful INSERTS, but on the 11th INSERT,
    the application fails for some reason (say for example, i tried to
    perform an INSERT into a table that doesn't exist). logically, i
    should stop execution and display some sort of error message. but,
    i've already ran a bunch of INSERTS so what do i do? thanks
     
    , Apr 24, 2007
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > hello. i'm trying to incorporate error handling into my application,
    > but i've run into a dilemma.
    >
    > i've already performed 10 successful INSERTS, but on the 11th INSERT,
    > the application fails for some reason (say for example, i tried to
    > perform an INSERT into a table that doesn't exist). logically, i
    > should stop execution and display some sort of error message. but,
    > i've already ran a bunch of INSERTS so what do i do? thanks
    >


    Look up your DB platform's help documentation on:-

    BEGIN TRANSACTION
    COMMIT TRANSACTION
    ROLLBACK TRANSACTION
     
    Anthony Jones, Apr 24, 2007
    #2
    1. Advertising

  3. Guest

    thanks. that helps out alot.

    i have another question. i have the following test code:

    '-------------------------------beg of
    code------------------------------------------------

    Function ErrorsFound(mycon) '-----------------beg of function
    Dim myError

    If mycon.State <> 1 Then
    eStr = "something wrong with db"
    ErrorsFound = True
    ElseIf mycon.Errors.Count > 0 Then
    For Each myError in mycon.Errors
    If myError.Number <> 0 Then
    eStr = eStr & "<P>"& myError.Number & " - " & myError.Description &
    "</P>"
    ErrorsFound = True
    End If
    Next
    ElseIf err.number <> 0 then
    response.Write(Err.Description&"<br><br>")
    ErrorsFound = True
    Else
    ErrorsFound = False
    End If
    End Function '-----------------end of function


    query1 = "insert into players (lastname, firstname, rbi) values
    ('cruise','beta',44)"
    query2 = "insert into players (lastname, firstname, rbi) values
    ('jee','alison',57)"
    query3 = "insert into players (lastname, firstname, rbi) values ('van
    hudgeons','vanessa',123)"
    query4 = "insert into players (lastname, firstname, rbi) values
    ('fox','megan',99)"

    conn.BeginTrans
    conn.execute query1
    conn.execute query2
    conn.execute query3
    conn.execute query4
    If ErrorsFound(conn) = False Then
    conn.CommitTrans
    Response.Write "Committing Transaction...<br>"
    Else
    conn.RollbackTrans
    Response.Write "Rolling back transaction...<br>"
    End If
    '-------------------------------end of
    code------------------------------------------------

    for kicks, i changed the name of the table to force an error. i
    changed it for the first query, then the second, then the third, and
    finally the last. the thing i'm wondering is when i changed the
    first, second, and third queries, the ErrorsFound function will enter
    the 2nd "elseif," but for the fourth query, the function will enter
    the 1st "elseif." why is that?

    thanks
     
    , Apr 24, 2007
    #3
  4. wrote:
    > thanks. that helps out alot.
    >
    > i have another question. i have the following test code:
    >
    > '-------------------------------beg of
    > code------------------------------------------------
    >
    > Function ErrorsFound(mycon) '-----------------beg of function
    > Dim myError
    >
    > If mycon.State <> 1 Then
    > eStr = "something wrong with db"
    > ErrorsFound = True
    > ElseIf mycon.Errors.Count > 0 Then
    > For Each myError in mycon.Errors
    > If myError.Number <> 0 Then
    > eStr = eStr & "<P>"& myError.Number & " - " & myError.Description &
    > "</P>"
    > ErrorsFound = True
    > End If
    > Next
    > ElseIf err.number <> 0 then
    > response.Write(Err.Description&"<br><br>")
    > ErrorsFound = True
    > Else
    > ErrorsFound = False
    > End If
    > End Function '-----------------end of function
    >
    >
    > query1 = "insert into players (lastname, firstname, rbi) values
    > ('cruise','beta',44)"
    > query2 = "insert into players (lastname, firstname, rbi) values
    > ('jee','alison',57)"
    > query3 = "insert into players (lastname, firstname, rbi) values ('van
    > hudgeons','vanessa',123)"
    > query4 = "insert into players (lastname, firstname, rbi) values
    > ('fox','megan',99)"
    >
    > conn.BeginTrans
    > conn.execute query1
    > conn.execute query2
    > conn.execute query3
    > conn.execute query4
    > If ErrorsFound(conn) = False Then
    > conn.CommitTrans
    > Response.Write "Committing Transaction...<br>"
    > Else
    > conn.RollbackTrans
    > Response.Write "Rolling back transaction...<br>"
    > End If
    > '-------------------------------end of
    > code------------------------------------------------
    >
    > for kicks, i changed the name of the table to force an error. i
    > changed it for the first query, then the second, then the third, and
    > finally the last. the thing i'm wondering is when i changed the
    > first, second, and third queries, the ErrorsFound function will enter
    > the 2nd "elseif," but for the fourth query, the function will enter
    > the 1st "elseif." why is that?
    >

    You need to check for errors after each execution, rolling back if errors
    occur. Successful executions clear the errors.

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Apr 24, 2007
    #4
  5. Guest

    thanks. that helps out alot.

    i have another question. i have the following test code:

    '-------------------------------beg of
    code------------------------------------------------

    Function ErrorsFound(mycon) '-----------------beg of function
    Dim myError

    If mycon.State <> 1 Then
    eStr = "something wrong with db"
    ErrorsFound = True
    ElseIf mycon.Errors.Count > 0 Then
    For Each myError in mycon.Errors
    If myError.Number <> 0 Then
    eStr = eStr & "<P>"& myError.Number & " - " & myError.Description &
    "</P>"
    ErrorsFound = True
    End If
    Next
    ElseIf err.number <> 0 then
    response.Write(Err.Description&"<br><br>")
    ErrorsFound = True
    Else
    ErrorsFound = False
    End If
    End Function '-----------------end of function


    query1 = "insert into players (lastname, firstname, rbi) values
    ('cruise','beta',44)"
    query2 = "insert into players (lastname, firstname, rbi) values
    ('jee','alison',57)"
    query3 = "insert into players (lastname, firstname, rbi) values ('van
    hudgeons','vanessa',123)"
    query4 = "insert into players (lastname, firstname, rbi) values
    ('fox','megan',99)"

    conn.BeginTrans
    conn.execute query1
    conn.execute query2
    conn.execute query3
    conn.execute query4
    If ErrorsFound(conn) = False Then
    conn.CommitTrans
    Response.Write "Committing Transaction...<br>"
    Else
    conn.RollbackTrans
    Response.Write "Rolling back transaction...<br>"
    End If
    '-------------------------------end of
    code------------------------------------------------

    for kicks, i changed the name of the table to force an error. i
    changed it for the first query, then the second, then the third, and
    finally the last. the thing i'm wondering is when i changed the
    first, second, and third queries, the ErrorsFound function will enter
    the 2nd "elseif," but for the fourth query, the function will enter
    the 1st "elseif." what makes the fourth query any different than the
    first 3 that it won't enter the same "if" branch? what's going on?

    thanks
     
    , Apr 25, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PT
    Replies:
    0
    Views:
    4,251
  2. Brett Sheeran

    Log4j Not Rolling Files

    Brett Sheeran, Feb 9, 2004, in forum: Java
    Replies:
    1
    Views:
    7,493
    Oscar kind
    Feb 23, 2004
  3. marty

    rolling back 24 hour times

    marty, Nov 12, 2003, in forum: C Programming
    Replies:
    5
    Views:
    618
    Eric Sosman
    Nov 12, 2003
  4. M Wells
    Replies:
    0
    Views:
    364
    M Wells
    Mar 3, 2004
  5. Replies:
    0
    Views:
    252
Loading...

Share This Page