Board index » delphi » dbexpress in thread locking application

dbexpress in thread locking application


2004-05-22 06:32:59 PM
delphi234
Im using a thread which creates several TSQLQuerys that all use a single
connection from the Data Module.
and operations on the TSQLQueries are done within critical sections, however
when freeing the thread and destroying the TSQLQueries the application locks
up - the following lines is the output from MadExcept.
77f82870 ntdll.dll NtWaitForSingleObject < - it never returns
from this
77f88225 ntdll.dll RtlpWaitForCriticalSection
00407290 Flow.exe System @IntfClear
004fb7ca Flow.exe SqlExpr TCustomSQLDataSet.FreeCursor
I use the following (simplified) code to create and free the worker thread.
(worker thread properties are = FreeOnTerminate = False, CreateSuspended =
False)
FThread := TActionThread.Create(FActionID);
WaitForSingleObject(FThread.Handle, INFINITE);
FreeAndNil(FThread); //<-- during the freeing of the thread it frees the
queries which cause the lock
i know this looks like it defeats the purpose of the thread becuase im
waiting for it after creating it, but this is also run within a another
thread on a timed basis.
what is the correct way to use the TSQLQuery from within a thread? do i
need a seperate TSQLConnection as a property of the thread?
any ideas would be much appreciated
main thread ($5f0):
77f82870 ntdll.dll NtWaitForSingleObject <-lock up occurs here when the
wait never returns.
77f88225 ntdll.dll RtlpWaitForCriticalSection
00407290 Flow.exe System @IntfClear
004fb7ca Flow.exe SqlExpr TCustomSQLDataSet.FreeCursor
004eb596 Flow.exe DB 8901 TDataSet.CloseCursor
004fb7b0 Flow.exe SqlExpr TCustomSQLDataSet.CloseCursor
004eb45f Flow.exe DB 8853 TDataSet.SetActive
004eb264 Flow.exe DB 8805 TDataSet.Close
004fb15d Flow.exe SqlExpr TCustomSQLDataSet.Destroy
004ffe59 Flow.exe SqlExpr TSQLQuery.Destroy
004043dc Flow.exe System TObject.Free
0077edd3 Flow.exe classFloModule 358 TFloModule.Destroy
0064f641 Flow.exe ClassFloDBCon 92 TFloDBCon.Destroy
004043dc Flow.exe System TObject.Free
007775cc Flow.exe ClassFloDataSource 522 TFloDataSource.Destroy
006803d6 Flow.exe ClassFloFileSource 206 TFloFileSource.destroy
 
 

Re:dbexpress in thread locking application

Hello !
Quote
any ideas would be much appreciated
For ideas, it would be interesting to get:
- what RDBMS do you use ?
- what dbExpress driver version do you use ?
- what SQL command you are running in{*word*154} up query ?
Regards,
Dmitry
SAPx - Delphi to SAP R/3 direct access
Saphir - SAP R/3 metadata on your fingertips
MetaBase - ERWIN model in Delphi applications
NCOCI8 - Freeware Delphi to ORACLE direct access
 

Re:dbexpress in thread locking application

hello
thanks for reply
(1) my application connects to several different RDBMS, but the most
commonly used are interbase, MS SQL, ms access, and MySQL. the problem
happens on all the RDBMS.
(2) i am using the most up-to-date dbexpress drivers with Delphi 7 as
provided in the updates from borlands website. (d7_ent_upd1.exe,
d7_db2update.zip)
(3) it is a SELECT command
everything works fine and the application does not hang until i am freeing
the queries after using them. it seems that the problem is caused when
TCustomSQLDataSet.FSQLCursor is set to nil which causes the interface to be
freed by IntfClear.
thanks
Cameron
"Dmitry Arefiev [gs-soft.ru]" <XXXX@XXXXX.COM>writes
Quote
Hello !

>any ideas would be much appreciated

For ideas, it would be interesting to get:
- what RDBMS do you use ?
- what dbExpress driver version do you use ?
- what SQL command you are running in{*word*154} up query ?

Regards,
Dmitry

--
Dmitry L. Arefiev, gs-soft Company, www.gs-soft.com
Personal - www.da-soft.com

SAPx - Delphi to SAP R/3 direct access
Saphir - SAP R/3 metadata on your fingertips
MetaBase - ERWIN model in Delphi applications
NCOCI8 - Freeware Delphi to ORACLE direct access


 

Re:dbexpress in thread locking application

Hello !
I cant reproduce your issue ...
Quote
everything works fine and the application does not hang until i am freeing
the queries after using them. it seems that the problem is caused when
TCustomSQLDataSet.FSQLCursor is set to nil which causes the interface to be
freed by IntfClear.
Yes ... Looks like a bug in DbExpress code. But i am not sure.
You can enter your report with steps to reproduce into QC.
I will suggest to try following:
1) May be you are creating queries in one thread and freeing in
another one ? Try to do in the same thread.
2) May be you are freeing TSQLConnection before queries and
connection is destroying in another thread, than queries ?
3) May be to try to fetch all data from queries, then close and
unprepare them, then free. After that close connection ?
etc and etc
In other words, without dbExpress sources i can just speculate
what and how ...
Regards,
Dmitry
SAPx - Delphi to SAP R/3 direct access
Saphir - SAP R/3 metadata on your fingertips
MetaBase - ERWIN model in Delphi applications
GISx - GIS system booster and simplifier
NCOCI8 - Freeware Delphi to ORACLE direct access
SCard - Complete PKCS11 and X509 solution
 

Re:dbexpress in thread locking application

hi dmitry
thanks for you replys. i have found the problem though and it is because my
TSQLQuery in the threads where using TSQLConnections in the main application
thread. I have made each thread use there own connection, and the problem
is resolved.
i was ignoring the basic rule of threads that was a must with the BDE and
TSessions.
thanks
Cameron
"Dmitry Arefiev [gs-soft.ru]" <XXXX@XXXXX.COM>writes
Quote
Hello !


I cant reproduce your issue ...

>everything works fine and the application does not hang until i am
freeing
>the queries after using them. it seems that the problem is caused when
>TCustomSQLDataSet.FSQLCursor is set to nil which causes the interface to
be
>freed by IntfClear.

Yes ... Looks like a bug in DbExpress code. But i am not sure.
You can enter your report with steps to reproduce into QC.

I will suggest to try following:
1) May be you are creating queries in one thread and freeing in
another one ? Try to do in the same thread.
2) May be you are freeing TSQLConnection before queries and
connection is destroying in another thread, than queries ?
3) May be to try to fetch all data from queries, then close and
unprepare them, then free. After that close connection ?

etc and etc

In other words, without dbExpress sources i can just speculate
what and how ...

Regards,
Dmitry

--
Dmitry L. Arefiev, gs-soft Company, www.gs-soft.com
Personal - www.da-soft.com

SAPx - Delphi to SAP R/3 direct access
Saphir - SAP R/3 metadata on your fingertips
MetaBase - ERWIN model in Delphi applications
GISx - GIS system booster and simplifier
NCOCI8 - Freeware Delphi to ORACLE direct access
SCard - Complete PKCS11 and X509 solution