Nested Try..Except blocks and incorrect commit scope 
Author Message
 Nested Try..Except blocks and incorrect commit scope

Hey out there,

I'm having a bit of a problem with a delphi 1.0 application running
against SQL server 6.5 tables.

I have several function which perform updates to individual tables in a
nested fashion.  The problem is, when I encounter an error, I rollback,
but only those changes made to the table which caused the error are
rolled back.  

sample code:

with mydatabase do begin

   try
      startTransaction;
      MyParentObject.insert;
      commit;
   except
      on EDatabaseError do
         begin
            rollback;
            raise;
         end;
    end;

within MyParentObject, I execute this code:

try
   insertSQL.execsql;  {a query with insert logic}
   for i := 1 to childrenCount do
      try
        myChildObject.insert;
      except on EDatabaseError do raise;
      end;
except on EDatabaseError do Raise;
end;

and so on........

I've marched through the code in the de{*filter*} and see that the commit
does not get executed and that the rollback does execute because at each
level of try..except I re-raise the exception until I am at the root
try..except block.  

Still, when I go and check the database, all changes made prior to the
query which failed are committed.  All queries use the same Tdatabase
instance.  

Any thoughts??

Thanks in advance for your help.
Paul Keegstra



Mon, 22 Feb 1999 03:00:00 GMT
 Nested Try..Except blocks and incorrect commit scope

Quote:

>I'm having a bit of a problem with a delphi 1.0 application running
>against SQL server 6.5 tables.

>I have several function which perform updates to individual tables in a
>nested fashion.  The problem is, when I encounter an error, I rollback,
>but only those changes made to the table which caused the error are
>rolled back.  

Broaden the scope of your transaction - I would place it in the
outermost try..except block instead of the innermost one.  You can't
roll back changes that didn't occur within a transaction...


Sat, 06 Mar 1999 03:00:00 GMT
 
 [ 2 post ] 

 Relevant Pages 

1. Try/except block in SQL server :)

2. SQL 7.0 leaves an open transaction, blocking all users except the one

3. SQL 7.0 leaves an open transaction, blocking all users except the one

4. Scope of a commit in a multi-threaded app

5. Help with try...except statements

6. Problem with try .. except, exception handler

7. Nested procedures - scope problems?

8. Try Except to suppress error box??

9. Try .. Except

10. try...except-statement in MSSQL??

11. Try ... Except

12. try...except-statement in MSSQL??


 
Powered by phpBB® Forum Software