473,765 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1931

<br**********@g mail.comwrote in message
news:11******** *************@c 18g2000prb.goog legroups.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(myc on) '-----------------beg of function
Dim myError

If mycon.State <1 Then
eStr = "something wrong with db"
ErrorsFound = True
ElseIf mycon.Errors.Co unt 0 Then
For Each myError in mycon.Errors
If myError.Number <0 Then
eStr = eStr & "<P>"& myError.Number & " - " & myError.Descrip tion &
"</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','vane ssa',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(con n) = False Then
conn.CommitTran s
Response.Write "Committing Transaction...< br>"
Else
conn.RollbackTr ans
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**********@gm ail.com wrote:
thanks. that helps out alot.

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

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

Function ErrorsFound(myc on) '-----------------beg of function
Dim myError

If mycon.State <1 Then
eStr = "something wrong with db"
ErrorsFound = True
ElseIf mycon.Errors.Co unt 0 Then
For Each myError in mycon.Errors
If myError.Number <0 Then
eStr = eStr & "<P>"& myError.Number & " - " & myError.Descrip tion &
"</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','vane ssa',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(con n) = False Then
conn.CommitTran s
Response.Write "Committing Transaction...< br>"
Else
conn.RollbackTr ans
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(myc on) '-----------------beg of function
Dim myError

If mycon.State <1 Then
eStr = "something wrong with db"
ErrorsFound = True
ElseIf mycon.Errors.Co unt 0 Then
For Each myError in mycon.Errors
If myError.Number <0 Then
eStr = eStr & "<P>"& myError.Number & " - " & myError.Descrip tion &
"</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','vane ssa',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(con n) = False Then
conn.CommitTran s
Response.Write "Committing Transaction...< br>"
Else
conn.RollbackTr ans
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
2859
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 mean like in this case I can see if the record is being added duplicate then I can always check for duplicate records and throw a message. but I will face so many errors like this??? do we have a list ..whereby I can get all the error numbers and...
8
2259
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 error resume next. For 1. This is a general handling. I want to handle local error. Maybe i do special thing when error occured. For 2. I have to write alot of lines code. I have to control every line.
1
1958
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 Node:000 PID:2608(db2syscs.exe) TID:3100 Appid:AC10049E.G79D.00F866005503 data management sqldEndNoLogList Probe:1 Database:NJIPD ADM5530E The COMMIT processing of table "TBSPACEID=4.TABLEID=2828" that used NOT LOGGED INITIALLY has been...
1
1691
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 as an exception condition. This also means that implementation of user defined exceptions would be in trouble. Note that the execution would not be affected(for now, i.e. without user defined exceptions), it's just a compiler vulnerability.
8
3876
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 to the standard, any error during an SQL statement should cause the rollback of that statement. InnoDB sometimes rolls back only part of the statement, or the whole transaction. The following items describe how InnoDB performs error handling:" ...
0
1192
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, something fails (perhaps trying to perform an INSERT into a table that doesn't exist). logically, i should stop execution of the page and display some sort of error message. but, since i've already run 10 successful INSERT queries before the error...
1
2381
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)I set up error handling on a subform that requires a field in the main subform to be clicked. If the user doesn't select one I get the constraint violation. How can I cause the subform to default back to as if nothing was typed there. Basically...
2
19488
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
2897
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
9566
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9946
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8830
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5413
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.