try block processing path

G

Guest

In the following try catch block can I guarantee that part b will not execute
if part a throws exception

try {
part a
part b
}
catch (Exception ex) {
do something
}
finally {
dispose of any thing needed
}

I am doing a DB update in part a and an insert in part b based on part a
data. I need to make sure that part a is successful before doing part b.

Part b could be multiple items from a listbox that may or may not be
different then what's already in the table. I could delete all and then
insert these but I have to make sure that part a completed successfully. Then
if part b fails I need to rollback any of the changes.

Thanks
 
E

Eliyahu Goldin

The answer to your question is yes, it is guaranteed.

May be you should consider using database transactions to ensure data
integrity.

Eliyahu
 
G

Guest

I would love to use DB transactions however the situation I am in is not
feasible necessarily.

I am updating one record in one table and then I have to do a loop through
an arraylist and perform an insert into another table. I have decided it will
be best to do a delete then insert instead of doing an update or add routine.
My problem is I don't want one change taking place if the other fails.

So basically I would like to execute many SQLCommands under one transaction
object. I believe I can do this with ADO.Net transactions on the page. I
normally use all stored procedures and perform my transactions from there but
now I needed to execute all the sp commands under a single transaction object.

Marty
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top