Board index » delphi » Problems with ADO and Multithreading: List Index Out Of Bounds

Problems with ADO and Multithreading: List Index Out Of Bounds


2006-08-21 11:46:30 PM
delphi252
Hi!
I've realized an application with Delphi 7 or Delphi 2006 and ADO
connection to a Microsoft Access Database (Microsoft Jet 4.1 Connection)
under Windows XP Professional. Application works very fine until I tried to
made simultaneous concurrent query to the Database.
Using multithreading procedures to operate with database, delphi raises
this runtime exception: "List Index Out Of Bounds (99)", where the number
showed between parentesis increases each time exception is raised (only
recently I have discovered this number is the number of datasets in
connection: TADOConnection.DataSetCount).
When this error occurs memory occupation of the program increases
drammatically (I think beacause datasets are not destroyed), and after
raising some errors, another exception (Access Violation) is raised and
there is no way to recover the application (I must kill the process in Task
Manager).
Please, can anyone help me?
Thanks a lot,
Antonio
Here there's a simple example:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DB, ADODB, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
ActiveX;
{$R *.dfm}
function f(p: Pointer): Integer;
var
Q: TADOQuery;
begin
Q:= TADOQuery.Create(nil);
Q.Connection:=form1.ADOConnection1;
Q.SQL.Add('select * from COMANDE');
Q.Open;
while not Q.Eof do begin
sleep(10);
Q.Next;
end;
Q.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
tid: Cardinal;
begin
for i:=0 to 100 do begin
BeginThread(nil,0,f,nil,0,tid);
end;
end;
initialization
CoInitializeEx(nil, COINIT_MULTITHREADED);
finalization
CoUninitialize;
end.
 
 

Re:Problems with ADO and Multithreading: List Index Out Of Bounds

Hello Antonio
You should use single connection object per thread at time.
And not share it between threads.
Regards,
Dmitry
--
Dmitry Arefiev - www.da-soft.com
AnyDAC - Oracle, MySQL, MS SQL, MSAccess, IBM DB2, Sybase
ASA, DbExpress, ODBC freeware data access framework
gs-soft AG - www.gs-soft.com
SAPx - Delphi to SAP R/3 direct access
Saphir - SAP R/3 metadata at your fingertips
MetaBase - ERWIN model in Delphi applications
 

Re:Problems with ADO and Multithreading: List Index Out Of Bounds

I tried to create (and destroy) TADOConnection in each separated thread, but
still Delphi raises the same exceptions!
"Dmitry Arefiev" <XXXX@XXXXX.COM>ha scritto nel messaggio
Quote
Hello Antonio

You should use single connection object per thread at time. And not share
it between threads.

Regards,
Dmitry

--
Dmitry Arefiev - www.da-soft.com
AnyDAC - Oracle, MySQL, MS SQL, MSAccess, IBM DB2, Sybase
ASA, DbExpress, ODBC freeware data access framework
gs-soft AG - www.gs-soft.com
SAPx - Delphi to SAP R/3 direct access
Saphir - SAP R/3 metadata at your fingertips
MetaBase - ERWIN model in Delphi applications

 

Re:Problems with ADO and Multithreading: List Index Out Of Bounds

Hi Brian,
"Brian Bushay TeamB" <XXXX@XXXXX.COM>ha scritto:
Quote
You need to create and destroy all database components that you use in
each
thread.
I've already tried to do this, but with no results!
Quote
What line of code triggers this error?
I don't know what line of code triggers this error because de{*word*81} show me
only a compiled (Assembly) section of code when I try to catch the exception
(I suppose the error is raised internally the TADOQuery component).
Best Regard,
Antonio