And as another hint for programming-style:

if - statements of the form

if boolexpression = true then ...
if boolexpression <> true then ...
can be written as 
if boolexpression then ...
if not boolexpression then ...
in your case
         if not datamodule2.IBSQL1.Transaction.Active then
         begin

or even denser and more readable

with Datamodule2.IBSQL1.Transaction do 
     if not Active then StartTransaction;

For better reading (imagine, you have to analyze your program again some months 
later)
rename Datamodule2 to DatabaseModule (or something more meaningful) and
rename IBSQL1 to something describing with some meaningful characters what it 
is made for.

By the way, you do not need to start the transaction yourself, the default 
transaction will be started automatically when you access your tables, but you 
should commit it in your program.
 
Have fun
Bob

*********** Am 14.04.2010 21:34:28 schrieb ihnen c80840 <[email protected]> 
***************
>     Well  dduuhh on my part.  I changed the if to:
>     
>         if datamodule2.IBSQL1.Transaction.Active <> true then
>         begin
>            datamodule2.IBSQL1.Transaction.StartTransaction;
>         end;
>     
>     Now all is fine.  Thanks.
>     
>     --- In [email protected], "j.me...@..." <j.me...@...> wrote:
>     >
>     > Are you loosing the connection to the database or to
>     > IBSQL1?
>     > To perform a commit (or a rollback) closes all tables the transaction 
> is connected to.
>     > That behaveour is by design.
>     > 
>     > Have fun
>     > Bob
>     >  
>     > *********** Am 14.04.2010 20:48:12 schrieb ihnen c80840 <c80...@...> 
> ***************
>     > >     
>     > >     Can someone tell me why I keep loosing connection to the database?
>     > >     
>     > >     
>     > >     procedure TForm3.ThisCommand1Click(Sender: TObject);
>     > >     begin
>     > >         datamodule2.IBSQL1.SQL.Clear;
>     > >         
> datamodule2.IBSQL1.SQL.Add(datamodule2.IBTable2.FieldByName('commands_').AsString+';');
>     > >         if datamodule2.IBSQL1.Transaction.Active = true then
>     > >         begin
>     > >             datamodule2.IBSQL1.Transaction.Rollback;
>     > >         end;
>     > >         datamodule2.IBSQL1.Transaction.StartTransaction;
>     > >         datamodule2.IBSQL1.Prepare;
>     > >         if (datamodule2.IBSQL1.Prepared = true) then
>     > >         begin
>     > >             datamodule2.IBSQL1.ExecQuery;
>     > >             datamodule2.IBSQL1.Transaction.CommitRetaining;
>     > >             // I've also tried: 
> datamodule2.IBSQL1.Transaction.CommitRetaining;
>     > >             // I lose the connection to the database on either
>     > >         end;
>     > >     end;
>     >
>     

Reply via email to