Subject | Threaded Query |
---|---|
Author | Matt Nielsen |
Post date | 2005-04-18T21:56:11Z |
Hello All,
I may be out in left field but here goes.
I want to have a application that has a single IB_Connection a single
query created inside a thread. I am doing this in a test mode.
Bacically the thread execute creates a data module and then executes
a query on that datamodule. The IB_Connection is set and everything
works fine as long as only one thread is running, but if I launch
mutiple threads then I get an error: "Error reading data from the
connection"
I have added the TIB_Seesion to the same data module as the
IB_Connection and have made sure the IB_Connection.IB_Session is set
to this session component but still get the same error.
Here is my code:
The form code:
procedure TAppMain.Button1Click(Sender: TObject);
var
_i: Integer;
begin
AppDB.FDatabase.IB_Session := AppDB.FSession;
AppDB.FDatabase.Open;
for _i := 1 to 2 do begin
with MyThreadTest.Create(False) do begin
FreeOnTerminate := True;
Resume;
end; {with}
end; {try}
end;
The Thread code:
procedure MyThreadTest.Execute;
var
_appquery: TAppQuery;
begin
_appquery := TAppQuery.Create(nil);
with _appquery do begin
try
GetEntity.Open;
Sleep(1500);
GetEntity.Close;
finally
Free;
end; {try}
end; {with}
end;
I may be out in left field but here goes.
I want to have a application that has a single IB_Connection a single
query created inside a thread. I am doing this in a test mode.
Bacically the thread execute creates a data module and then executes
a query on that datamodule. The IB_Connection is set and everything
works fine as long as only one thread is running, but if I launch
mutiple threads then I get an error: "Error reading data from the
connection"
I have added the TIB_Seesion to the same data module as the
IB_Connection and have made sure the IB_Connection.IB_Session is set
to this session component but still get the same error.
Here is my code:
The form code:
procedure TAppMain.Button1Click(Sender: TObject);
var
_i: Integer;
begin
AppDB.FDatabase.IB_Session := AppDB.FSession;
AppDB.FDatabase.Open;
for _i := 1 to 2 do begin
with MyThreadTest.Create(False) do begin
FreeOnTerminate := True;
Resume;
end; {with}
end; {try}
end;
The Thread code:
procedure MyThreadTest.Execute;
var
_appquery: TAppQuery;
begin
_appquery := TAppQuery.Create(nil);
with _appquery do begin
try
GetEntity.Open;
Sleep(1500);
GetEntity.Close;
finally
Free;
end; {try}
end; {with}
end;