Board index » delphi » dbexpress with multiple threads

dbexpress with multiple threads


2004-10-26 01:10:07 AM
delphi195
Hi,
I have the following function (see below) which is accessed by multiple
threads. When I use 1 thread, everything works fine, but when I use multiple
threads accessing this code I get errors like "dbExpress: invalid
precision".
Now my questions are:
1) is it allowed to let multiple threads access the same part of code
2) can the dbExpress TSQLConnection handle multiple query's at the same time
Any help for solving this problem is welcome.
Jurgen
--begin of function--
function TIQDBC.SelectStatement(Statement: string): TSQLQuery;
var SQLQuery: TSQLQuery;
begin
SQLQuery:=TSQLQuery.Create(nil);
SQLQuery.SQLConnection:=SQLConnection;
SQLQuery.SQL.Add(Statement);
SQLQuery.Open;
Result:=SQLQUERY;
end;
--end of function
 
 

Re:dbexpress with multiple threads

Jurgen Simons writes:
Quote
Hi,

I have the following function (see below) which is accessed by multiple
threads. When I use 1 thread, everything works fine, but when I use multiple
threads accessing this code I get errors like "dbExpress: invalid
precision".

Now my questions are:
1) is it allowed to let multiple threads access the same part of code
Yes. As long as you lock the code appropriately.
2) can the dbExpress TSQLConnection handle multiple query's at the same time
Yes. But in the context of a thread, one TSQLConnection per thread. So
if you have one thread running 3 queries, that is OK. Three threads
sharing on TSQLConnection, not good.
Quote

Any help for solving this problem is welcome.

Jurgen

--begin of function--

function TIQDBC.SelectStatement(Statement: string): TSQLQuery;
var SQLQuery: TSQLQuery;
begin
SQLQuery:=TSQLQuery.Create(nil);
SQLQuery.SQLConnection:=SQLConnection;
SQLQuery.SQL.Add(Statement);
SQLQuery.Open;
Result:=SQLQUERY;
end;

--end of function


--
Thomas Miller
Delphi Client/Server Certified Developer
BSS Accounting & Distribution Software
BSS Enterprise Accounting FrameWork
www.bss-software.com
sourceforge.net/projects/dbexpressplus
 

Re:dbexpress with multiple threads

I implemented my system using the one thread - one TSQLConnection rule, but
I get errors (access violations) when I switch to another program (clicking
in the taskbar) while my threads are executing. Every thread has its own
TSQLConnection component. The problem only arises when doing select
statements using the code below.
Jurgen
"Thomas Miller" <XXXX@XXXXX.COM>writes
Quote


Jurgen Simons writes:

>Hi,
>
>I have the following function (see below) which is accessed by multiple
>threads. When I use 1 thread, everything works fine, but when I use
multiple
>threads accessing this code I get errors like "dbExpress: invalid
>precision".
>
>Now my questions are:
>1) is it allowed to let multiple threads access the same part of code
Yes. As long as you lock the code appropriately.
>2) can the dbExpress TSQLConnection handle multiple query's at the same
time
Yes. But in the context of a thread, one TSQLConnection per thread. So
if you have one thread running 3 queries, that is OK. Three threads
sharing on TSQLConnection, not good.
>
>Any help for solving this problem is welcome.
>
>Jurgen
>
>--begin of function--
>
>function TIQDBC.SelectStatement(Statement: string): TSQLQuery;
>var SQLQuery: TSQLQuery;
>begin
>SQLQuery:=TSQLQuery.Create(nil);
>SQLQuery.SQLConnection:=SQLConnection;
>SQLQuery.SQL.Add(Statement);
>SQLQuery.Open;
>Result:=SQLQUERY;
>end;
>
>--end of function
>
>

--
Thomas Miller
Delphi Client/Server Certified Developer
BSS Accounting & Distribution Software
BSS Enterprise Accounting FrameWork

www.bss-software.com
sourceforge.net/projects/dbexpressplus