473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

error handling - rolling back changes

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 '07 #1
4 1913

<br**********@gmail.comwrote in message
news:11*********************@c18g2000prb.googlegro ups.com...
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

Apr 24 '07 #2
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 '07 #3
br**********@gmail.com 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"
Apr 24 '07 #4
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 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: monika | last post by:
hi ... I want to do error handling in my application. I have made a complete application. but when I encounter errors (like mentioned below) I want to do error handling. how can I do it? I...
8
by: Erencans | last post by:
Hi to all, I want to error handling in ASP. But i think that ASP is not enough for error handling. I have got two chance. 1. I can prapare an error page and control throught IIS. 2. I can use on...
1
by: xixi | last post by:
hi, we are using db2 v8.1 win 64 bit with fp3. i get this error message from the control panel : Administrative Tools, Event Viewer, application 2003-10-22-17.52.43.850000 Instance:DB2 ...
1
by: Paramveer.Singh | last post by:
Hi all! I was looking into the postgres8.0 code for exception handling, and it seems that the grammer treats an exception condition as opt_lblname. This means that I can pass any arbitrary string...
8
by: Michael Paesold | last post by:
I just read this in the MySQL manual: (http://dev.mysql.com/doc/mysql/en/InnoDB_Error_handling.html) "Error handling in InnoDB is not always the same as specified in the SQL standard. According...
0
by: brendan.wong | last post by:
hello. i'm trying to incorporate some error handling into my web app, but i'm not sure how to go about it in this case. say for example, i already ran 10 INSERTS, then on my 11th INSERT,...
1
by: brent78 | last post by:
I have 2 questions. 1)How can I do a setfocus on the first item in a combo box populated with a query. I figured I could somehow use the index of 0 but I can't figure out the syntax to do it....
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.