Board index » delphi » Thread freezes

Thread freezes

HI,

I'm trying to do some background queries to my SQL database (Adabas D from
Software AG) via BDE.
I'm using a TSession, TDatabase, TQuery object and assigned an unique name
for each started thread.

After starting the first, which runs for some minutes, I'm starting a second
one which should return immediately. However this second one freezes at
TQuery.Open.

I've tried almost everything but could not find the cause why this happens.

Any ideas?
Thanks,
--
Michael Fritz

Please replace localhost with kermi.de when mailing directly..
mailto: Fritz.Michael@localhost

 

Re:Thread freezes


Quote
"Michael Fritz" <fritz.michael@SP_AM.kermi.de> wrote in message

news:3b77d3f5_2@dnews...

Quote

> I'm trying to do some background queries to my SQL database (Adabas D from
> Software AG) via BDE.
> I'm using a TSession, TDatabase, TQuery object and assigned an unique name
> for each started thread.

> After starting the first, which runs for some minutes, I'm starting a
second
> one which should return immediately. However this second one freezes at
> TQuery.Open.

Does each thread object contain its own instances of these components and is
creating them and setting their connections to each other when the thread is
created?

--
Wayne Niddery (Logic Fundamentals, Inc.)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
"Some see private enterprise as a predatory target to be shot, others as a
cow to be milked, but few are those who see it as a sturdy horse pulling the
wagon." - Winston Churchill

Re:Thread freezes


"Wayne Niddery [TeamB]" <wnidd...@aci.on.ca> schrieb

Wayne,

Quote
> Does each thread object contain its own instances of these components and
is
> creating them and setting their connections to each other when the thread
is
> created?

Yes, each thread creates a single instance of TSession, TDatabase, TQuery
which are declared in the private section of my threads. I've included the
code below. Each of these threads uses a different name for SessionName and
DatabaseName.

However, as already stated, each thread waits for the other one at the point
TQuery.Open.

Any further ideas? Thanks.
....
constructor TCheckState.Create(Index : Integer; VARS : TGlobalVars);
   begin
       OnTerminate := ThreadEnd;
       FreeOnTerminate := True;
       inherited Create(True);
       Priority := tpLower;
// create TSession
           sesCheckState := TSession.Create(Nil);
           with sesCheckState do
           begin
               SessionName := 'sesCheckState';
           end;
// create TDatabase
           dbCheckState := TDatabase.Create(Nil);
           with dbCheckState do
           begin
               AliasName := BDE_ALIAS;
               SessionName := sesCheckState.SessionName;
               DataBaseName := 'dbCheckState';
               Params.Values['USER NAME'] := MASTER_LOGON;
               Params.Values['PASSWORD'] := MASTER_PW;
               LoginPrompt := False;
               KeepConnection := True;
           end;
// create TQuery
           qyCheckState := TQuery.Create(Nil);
           with qyCheckState do
           begin
               SessionName := sesCheckState.SessionName;
               DatabaseName := dbCheckState.DataBaseName;
           end;
// start Thread
           Resume;
    end;

--
Michael Fritz

Please replace localhost with kermi.de when mailing directly..
mailto: Fritz.Michael@localhost

Re:Thread freezes


Re:Thread freezes


Wayne,

do you think it might be a problem with the installation method of my BDE or
one of its options? The BDE is installed somewhere in our network.

Michael

--
Michael Fritz

Please replace localhost with kermi.de when mailing directly..
mailto: Fritz.Michael@localhost

Re:Thread freezes


Re:Thread freezes


Wayne,

I've just discovered when inserting dabase.connected := True  before
query.open, the second started thread waits at the point of connecting to
the database. Why?

So it has nothing to do with the query itself but with the database
connection.

--
Michael Fritz

Please replace localhost with kermi.de when mailing directly..
mailto: Fritz.Michael@localhost

Re:Thread freezes


Quote
"Michael Fritz" <fritz.michael@localhost> wrote in message

news:3b78e690$1_1@dnews...

Quote

> I've just discovered when inserting dabase.connected := True  before
> query.open, the second started thread waits at the point of connecting to
> the database. Why?

Your code appears to be fine for creating the components. I assume by your
statements that only one instance of TCheckState can ever exist at a time
and other threads are of other types? I also assume in the Execute method
you are simply setting the TDatabase open and then executing or opening the
query?

I know nothing about Adabas D, my only guess is that it's driver (ODBC?)
must not be able to handle multiple connections. If the first thread ends,
does the second thread then proceed?

I can tell you that I use background threads in applications with the BDE
with no problem. In my case I'm connecting to Interbase though.

--
Wayne Niddery (Logic Fundamentals, Inc.)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
"Some see private enterprise as a predatory target to be shot, others as a
cow to be milked, but few are those who see it as a sturdy horse pulling the
wagon." - Winston Churchill

Re:Thread freezes


Wayne,

thanks for reply.

Quote
> I assume by your statements that only one instance of TCheckState can ever
exist at a time
> and other threads are of other types?

Right, all threads have a different declaration and even work on different
tables.

Quote
> I also assume in the Execute method you are simply setting the
> TDatabase open and then executing or opening the query?

Right again. However at the moment I do not open TDatabase but doing a
TQuery.Open. Is this wrong at this place?

Quote
> I know nothing about Adabas D, my only guess is that it's driver (ODBC?)
> must not be able to handle multiple connections.

Of course Adabas is capable of handling multiple connections at one time. I
can use many running queries with some linked tables in M$ Access, using SQL
Explorer and a third party program which was buildt for use with this
database - all at the same time.

Quote
> If the first thread ends, does the second thread then proceed?

Yes it does. It may happen that one of the other started threads gains
access first at TQuery.Open, however each of the other one is waiting for
the one which started first to finish.

Quote
> I can tell you that I use background threads in applications with the BDE
> with no problem. In my case I'm connecting to Interbase though.

Do you use multiple queries in a NT service application, too? Do you think
I've to change some BDE settings? Could you provide me with an example
program, not that one Borland already delivers in the .\Demos directory?

I've tried to write my one Query-Tool to get multiple queries running each
in its own MDI window. That means I've got e.g. two windows opened and
running, or better: trying to run, its own query. However my problem is a
smentioned before: the second query waits at  TQuery.Open.

Michael

Re:Thread freezes


Note that while mostly BDE works fine with multiple threads, some API calls
are forbidden, because they access some internal objects that are locked
during query execution.
Examples are DbiGetCurrSession and DbiGetTranInfo.
If you call (directly or via VCL code) any of these (the above two are the
two I know of, but there are probably other), the thread freezes until other
database threads finish.

Also, BDE imposes some limitations to multithreaded app, like number of
sessions. We switched to SQL-direct, which works like a charm and transition
from BDE is smooth.
--
Robert

Re:Thread freezes


Robert,

thanks for your answer.

Why do you think will it work for Wayne when using Interbase as database
server?

Michael

Re:Thread freezes


Quote
"Michael Fritz" <spam_ath...@yahoo.de> wrote in message

news:3b7a622d_1@dnews...

Quote

> Right again. However at the moment I do not open TDatabase but doing a
> TQuery.Open. Is this wrong at this place?

That'll be fine. If that was a problem you'd get an understandable error
message here.

Quote
> Do you use multiple queries in a NT service application, too? Do you think
> I've to change some BDE settings? Could you provide me with an example
> program, not that one Borland already delivers in the .\Demos directory?

I have been writing multi-threaded NT Services recently in fact, but have
used IBX. I haven't done this with the BDE but I don't know why this would
make a difference.

Robert Cerry may have something. I'm not sure specifically why this would
arise with Adabas but not with Interbase, but I have no doubt difference
databases may exercise different functions within the BDE. This may
specifically have something to do with BDE's handling of ODBC connections
(Interbase and some others have "native" BDE drivers that do not use the
ODBC support).

--
Wayne Niddery (Logic Fundamentals, Inc.)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
"Some see private enterprise as a predatory target to be shot, others as a
cow to be milked, but few are those who see it as a sturdy horse pulling the
wagon." - Winston Churchill

Re:Thread freezes


Wayne,

thanks again for your answer.

If reading some other threads here in this NG, I' really have to doubt that
others got this multithreading issue running properly.

I cannot believe that all others use some SQL queries without the need of
the BDE, since you cannot get native drivers for any database out there,
right?

So, as a conclusion, you and Robert would search this annoying "bug" rather
in the architecture of the BDE and not in the ODBC drivers or perhaps in the
database itself, wouldn't you?

--
Michael Fritz

Please replace localhost with kermi.de when mailing directly..
mailto: Fritz.Michael@localhost

Re:Thread freezes


Re:Thread freezes


Hi Michael!

On Tue, 14 Aug 2001 10:18:38 +0200, "Michael Fritz"

Quote
<fritz.michael@SP_AM.kermi.de> wrote:
>constructor TCheckState.Create(Index : Integer; VARS : TGlobalVars);
>   begin
>       OnTerminate := ThreadEnd;
>       FreeOnTerminate := True;
>       inherited Create(True);
>       Priority := tpLower;
>// create TSession
>           sesCheckState := TSession.Create(Nil);
>           with sesCheckState do
>           begin
>               SessionName := 'sesCheckState';
>           end;
>// create TDatabase
>           dbCheckState := TDatabase.Create(Nil);
>           with dbCheckState do
>           begin
>               AliasName := BDE_ALIAS;
>               SessionName := sesCheckState.SessionName;
>               DataBaseName := 'dbCheckState';
>               Params.Values['USER NAME'] := MASTER_LOGON;
>               Params.Values['PASSWORD'] := MASTER_PW;
>               LoginPrompt := False;
>               KeepConnection := True;
>           end;
>// create TQuery
>           qyCheckState := TQuery.Create(Nil);
>           with qyCheckState do
>           begin
>               SessionName := sesCheckState.SessionName;
>               DatabaseName := dbCheckState.DataBaseName;
>           end;
>// start Thread
>           Resume;
>    end;

You have to assign unique name for every session and database object!
In the example above you set SessionName := 'sesCheckState' and
DataBaseName := 'dbCheckState' the same for every instance of the
thread! Try append some suffix like this:

SessionName := 'sesCheckState' + IntToStr(Int(Self));
DataBaseName := 'dbCheckState' + IntToStr(Int(Self));

There also may be a problem with Session private directory... but I am
not sure about that, it might work if you don't mess with the default
session's working and private directories.

tomi.

Go to page: [1] [2]

Other Threads