Subject Re: [IBO] Multi threaded access using in objects
Author Helen Borrie
At 12:02 PM 28/06/2004 +0000, you wrote:
>I have seen some posts on this subject.
>1. I need an explisit session.
>2. prorocol : cpTCP_IP
>3. Server : 127.0.0.1
>
>This code is inside the constructor of the thread. What is missing
>please.
>
> FSession := TIB_Session.Create(nil);

> FConnection := TIB_Connection.CreateForSession(nil,FSession);

Don't use CreateForSession: it has another purpose. And don't use nil
owners for anything but the TIB_Session.
FConnection := TIB_Connection.Create(FSession);

> FConnection.Protocol := cpTCP_IP;
> FConnection.Server := '127.0.0.1';

not
> FQuery := TIB_Query.CreateForSession(nil,FSession);

but
FQuery := TIB_Query.Create(FSession);

> FQuery.IB_Connection := FConnection;

Either
FQuery.IB_Transaction := FConnection.ib_transaction;

or, better, declare an explicit IB_Transaction (FTransaction :=
TIB_Transaction.Create(FSession);
FTransaction.[..........properties...........]
FTransaction.IB_Connection := FConnection;

then
FQuery.IB_Transaction := FConnection;

> FConnection.DatabaseName := 'c:\test.gdb';

Wrong here. You want

FConnection.Path := 'c:\test.gdb';

(DatabaseName would be '127.0.0.1:c:\test.gdb' but IBO doesn't need it)

> FConnection.Username := 'SYSDBA';
> FConnection.Password := 'masterkey';
> FConnection.Connect;
>
>The thread breaks on the fquery.execute line.

Something is missing here:
with FQuery do
begin
if not IB_Transaction.Started then
ib_Transaction.StartTransaction;
SQL.Add('a statement');
if not Prepared then Prepare;
Params[n].AsWhatever := something;
...
Execute;
end;

What are you executing? TIB_Query is for SELECT statements. Use
TIB_Cursor or TIB_DSQL for executable statements.

>When I create only one thread the code works fine.

What happens when subsequent threads run?

Helen