When I use multiple connections and try to use then simultaneously, the component seems to lost the connection with one of the connections, when a table on it have a lot of lines (here, the error occurs with more than 1223 lines).
Follow a example of code, (Delphi 2007 IDE, but should work in another version as well):
Code: Select all
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils,
Messages,
Variants,
Classes,
WideStrings,
DB,
SqlExpr,
DBXCommon;
var
SQLQuery, SQLQuery2: TSQLQuery;
SQL: String;
Sql1: string;
StartDate, EndDate: string;
cont: integer;
function ConnectToDatabase: TSQLConnection;
begin
try
Result := TSQLConnection.Create(nil);
// Change the path of the database here - we´re using Firebird 1.5
Result.Params.Text := 'DriverName=InterBase by Core Lab' + #$D#$A
+ 'Database=127.0.0.1:C:\DB_TEST.GDB' + #$D#$A
+ 'User_Name=sysdba'+ #$D#$A
+ 'Password=masterkey' + #$D#$A
+ 'SQLDialect=3' + #$D#$A
+ 'BlobSize=-1' + #$D#$A
+ 'InterBase by Core Lab TransIsolation=ReadCommited' + #$D#$A
+ 'WaitOnLocks=True' + #$D#$A
+ 'CharLength=1' +#$D#$A
+ 'EnableBCD=True' + #$D#$A
+ 'OptimizedNumerics=False'+#$D#$A
+ 'LongStrings=True'+#$D#$A
+ 'UseQuoteChar=False'+#$D#$A
+ 'FetchAll=False'+#$D#$A
+ 'UseUnicode=False'+#$D#$A;
Result.ConnectionName := 'InterBase by Core Lab';
Result.DriverName := 'InterBase by Core Lab';
Result.GetDriverFunc := 'getSQLDriverInterBase';
Result.LibraryName := 'dbexpida40.dll';
Result.VendorLib := 'fbclient.dll';
Result.Connected := true;
except
on E: Exception do
begin
Result := nil;
WriteLn(E.Message);
end;
end;
end;
begin
try
cont := 0;
SqlQuery := TSQLQuery.Create(nil);
SQLQuery.SQLConnection := ConnectToDatabase;
SQLQuery.SQL.Text := 'SELECT * from posicao;';
Writeln('Executing query...');
SQLQuery.ExecSQL;
writeln('Query ok...');
SQLQuery.Open;
SQLQuery.First;
while not SqlQuery.Eof do
begin
SqlQuery.Next;
// When the number of lines reaches 1223, the problem will occur
if ((cont mod 100) = 0) or (cont > 1220) then
// So we show the line number
writeln(cont);
Inc(cont);
SqlQuery2 := TSQLQuery.Create(nil);
// If I use the same connection created previously, the error doesn´t occur
// Like: SqlQuery2.SQLConnection := SqlQuery.SQLConnection;
// But creating a new connection it occurs whith any query here, inside the while
SqlQuery2.SQLConnection := ConnectToDatabase;
SqlQuery2.SQL.Text := 'select 1 from rdb$database;';
SqlQuery2.ExecSQL;
SqlQuery2.Open;
SqlQuery2.First;
FreeAndNil(SqlQuery2);
end;
except
on E: Exception do
WriteLn('Error : ' + E.Message );
end;
Writeln('END - TESTS OK!');
end.
Code: Select all
/******************************************************************************/
/*** Generated by IBExpert 2006.03.07 25/2/2008 15:23:46 ***/
/******************************************************************************/
SET SQL DIALECT 3;
SET NAMES NONE;
CREATE DATABASE 'C:\ProjetoConsole\DB_TEST.gdb'
USER 'SYSDBA' PASSWORD 'masterkey'
PAGE_SIZE 16384
DEFAULT CHARACTER SET NONE;
/******************************************************************************/
/*** Tables ***/
/******************************************************************************/
CREATE TABLE POSICAO (
COMUNICACAO_ID INTEGER NOT NULL,
LONGITUDE DOUBLE PRECISION,
LATITUDE DOUBLE PRECISION,
LOCALIZACAO VARCHAR(50),
DIRECAO SMALLINT,
DIRECAOSTR VARCHAR(2),
LOGRADOURO VARCHAR(100),
VALIDA SMALLINT NOT NULL,
VELOCIDADE INTEGER,
TIPO INTEGER DEFAULT 0 NOT NULL,
IGNICAO INTEGER default 2
);
Code: Select all
INSERT INTO POSICAO (COMUNICACAO_ID, LONGITUDE, LATITUDE, LOCALIZACAO, DIRECAO, DIRECAOSTR, LOGRADOURO, VALIDA, VELOCIDADE, TIPO, IGNICAO) VALUES (110481978, -51.886745, -23.431934, 'Maringa - PR', 0, 'N', 'Br 376, 1, 0, 0, 1);