Subject Re: [ib-support] Re: Can anyone help: Error reading data from the connection
Author Martijn Tonies
Hi,
> I have the same question as Martijn? Why can't threads share a db
> handle / connection? As long as they are not concurrently sharing
> the connection why can't this work?
>
> Prior to this problem, I started a connection each time a thread was
> created however this approach was too expensive, in terms of time.
> Each call into isc_attach_database() is around 1.5 seconds. Can I do
> anything about this?

Despite all this - it seems you need a different approach.

Think of a pool of workerthreads that each have their own db-connection.

When you need something done, pass a "job" to them and call the .Execute
method (or whatever language you're usign) - for example:

TWorkerThread = class(TThread)
IB_Connection: TIB_Connection;

procedure DoTask(aTask: TTask);

TTask = class(TObject)
//
procedure Execute(aConnection: TIB_Connection); virtual; abstract;
end;

TExecuteTask = class(TTask)
procedure ExecSQL(sql: string);
end;

procedure TWorkerThread .DoTask(aTask: TTask);
begin
aTask.Execute(IB_Connection);
end;


and so on - you probably get the idea...


With regards,

Martijn Tonies
InterBase Workbench - the developer tool for InterBase
http://www.upscene.com

Firebird Workbench - the developer tool for Firebird
http://www.upscene.com

Upscene Productions
http://www.upscene.com

"This is an object-oriented system.
If we change anything, the users object."