tsqlquery extrem slow with ado
Posted: 05.03.2020, 11:34
hi,
i use zeos 7.2.6.1 with lazarus 2.0.6 (32 bit) under win10 (64bit) and connect to an ms-sql server 2012. my problem is, that querys run with TZQuery are extremly slow and i can´t figured out why. i have a dbgrid, connected to a datasource and the datasource.dataset is connected to a tzquery.
the code simplyfied:
con:=TZConnection.Create(nil);
qry:=TZQuery.Create(nil);
qry.Connection:=con;
con.Protocol:='ado';
con.Database:='DRIVER=SQL Server;Trusted_Connection=Yes;SERVER=xxx;DATABASE=yyy;
con.Connected:=true;
qry.SQL.text:='SELECT TOP 500 * FROM dm.viewBatchOverview WHERE 1=1 AND 1=1 AND 1=1 AND 1=1 AND 1=1 AND 1=1 AND 1=1 ORDER BY Batch_ID DESC;';
qry.open;
(this 1=1 are paceholder for additional conditions that can be replaced in the sql without the need to complet regeneration of the entire statement)
this query takes 30 seconds.
in ms-sql management studio it takes 1 second
with lazarus native sqldb+odbc connection it takes 5 seconds.
what can i do to fix this? second question: what is the optimal connection method to an ms-sql-server without the needing of external .dll´s or drivers? i mean a simple connection string that works without any os-specifig adjustments like system dsn stuff...
thanks in advance.
i use zeos 7.2.6.1 with lazarus 2.0.6 (32 bit) under win10 (64bit) and connect to an ms-sql server 2012. my problem is, that querys run with TZQuery are extremly slow and i can´t figured out why. i have a dbgrid, connected to a datasource and the datasource.dataset is connected to a tzquery.
the code simplyfied:
con:=TZConnection.Create(nil);
qry:=TZQuery.Create(nil);
qry.Connection:=con;
con.Protocol:='ado';
con.Database:='DRIVER=SQL Server;Trusted_Connection=Yes;SERVER=xxx;DATABASE=yyy;
con.Connected:=true;
qry.SQL.text:='SELECT TOP 500 * FROM dm.viewBatchOverview WHERE 1=1 AND 1=1 AND 1=1 AND 1=1 AND 1=1 AND 1=1 AND 1=1 ORDER BY Batch_ID DESC;';
qry.open;
(this 1=1 are paceholder for additional conditions that can be replaced in the sql without the need to complet regeneration of the entire statement)
this query takes 30 seconds.
in ms-sql management studio it takes 1 second
with lazarus native sqldb+odbc connection it takes 5 seconds.
what can i do to fix this? second question: what is the optimal connection method to an ms-sql-server without the needing of external .dll´s or drivers? i mean a simple connection string that works without any os-specifig adjustments like system dsn stuff...
thanks in advance.