juris
asked on
multiple TQuery.Open lockup problems in TThread
Here is my story:
I wrote an application which
a) opens a query (which is placed on a form and is a simple select) on
the remote server, then closes it
FirstQuery.Open;
FirstQuery.Close;
b) creates a simple thread
TSimpleThread.Create;
c) the thread Create does this:
Query := TQuery.Create( MainForm );
Query.DatabaseName := 'database';
Inherited Create( False );
d) the thread Execute does this:
Query.SQL.Add( 'SELECT * FROM SOMETABLE' );
Query.Open;
Now at point d) the Query.Open just NEVER returns!!!
If I skip (comment out) a) it works just fine!
If I put c) and d) in the main thread it works just fine!
If I give nil or Application to TQuery.Create() instead of MainForm it
still hangs.
If I allocate the Query in d) it's hangs all the same. If I use a TTable
instead of FirstQuery it's all the same.
Once I somehow changed the program to hang even earlier on
Query.SQL.Add().
I tried to monitor the ODBC calls and the last ones I got was
PrepareStatement and ExecStatement or smth like that. Then you can just
wait for the results to be returned - forever.
So is it a problem with my thread creating or my query creating? Or is
it a BDE or an ODBC problem? Is it supposed to be that way?
I'm getting totally confused and desperate on this issue... :-(
Any ideas would be really appreciated.
I wrote an application which
a) opens a query (which is placed on a form and is a simple select) on
the remote server, then closes it
FirstQuery.Open;
FirstQuery.Close;
b) creates a simple thread
TSimpleThread.Create;
c) the thread Create does this:
Query := TQuery.Create( MainForm );
Query.DatabaseName := 'database';
Inherited Create( False );
d) the thread Execute does this:
Query.SQL.Add( 'SELECT * FROM SOMETABLE' );
Query.Open;
Now at point d) the Query.Open just NEVER returns!!!
If I skip (comment out) a) it works just fine!
If I put c) and d) in the main thread it works just fine!
If I give nil or Application to TQuery.Create() instead of MainForm it
still hangs.
If I allocate the Query in d) it's hangs all the same. If I use a TTable
instead of FirstQuery it's all the same.
Once I somehow changed the program to hang even earlier on
Query.SQL.Add().
I tried to monitor the ODBC calls and the last ones I got was
PrepareStatement and ExecStatement or smth like that. Then you can just
wait for the results to be returned - forever.
So is it a problem with my thread creating or my query creating? Or is
it a BDE or an ODBC problem? Is it supposed to be that way?
I'm getting totally confused and desperate on this issue... :-(
Any ideas would be really appreciated.
Or you using MSAccess tables?
ASKER
No, a remote RDBMS server.
sorry, then I can't help you, found on borland site an article about problems with access and threading queries.
found another article, maybe it helps :
http://www.borland.com/devsupport/delphi/ti_list/TI3005.html
http://www.borland.com/devsupport/delphi/ti_list/TI3005.html
ASKER
Hey, ZifNab, thanks, I'll read it and see if it helps but this sure looks good.
If you want, you can post the URL as an answer and I will grade you ASA as I get my code running!
:-)
Looks like you made my day better.
If you want, you can post the URL as an answer and I will grade you ASA as I get my code running!
:-)
Looks like you made my day better.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yeah, that really works.
Thanks again!
BTW I have another problem.
When ExecSQL-ing a simple 'DELETE FROM TABLENAME' query I get a 'table is read only' BDE error :-(. I tried both with RequestLive of True and False and it still wouldn't work.
Thanks again!
BTW I have another problem.
When ExecSQL-ing a simple 'DELETE FROM TABLENAME' query I get a 'table is read only' BDE error :-(. I tried both with RequestLive of True and False and it still wouldn't work.
Strange, I'll look after it.
Sorry for the delay.
How to you call this ExecSQL? :
Like this way? :
Query1.Prepare;
Query1.Params[0] := '.........'; {if you use parameters}
Query1.ExecSQL;
Query1.Refresh;
If not, try it this way and let me know.
How to you call this ExecSQL? :
Like this way? :
Query1.Prepare;
Query1.Params[0] := '.........'; {if you use parameters}
Query1.ExecSQL;
Query1.Refresh;
If not, try it this way and let me know.
ASKER
Didn't work that way too.
Right now I am selecting and then .Delete-ing... It works, although might be slower...
Right now I am selecting and then .Delete-ing... It works, although might be slower...
where did it go wrong?
ASKER
On Prepare;. SQL statement empty.
And you had declared a SQL ?
ASKER
What do you mean - declared?
You're quick:
Well, in Query.SQL := 'delete ....'
Well, in Query.SQL := 'delete ....'
ASKER
OK, sorry, commented that out.
It goes wrong on ExecSQL telling that 'Table is read only'.
It goes wrong on ExecSQL telling that 'Table is read only'.
I see my comment can be misinterpreted. With 'You're quick' I mean that you were quick with responding to my answer. Sorry if you thought of something else.
Strange. Then I can't help you for the moment. Sorry.
ASKER
Come on, that's OK. I know what you meant.
Although I admit it *was* stupid to comment the SQL assignment out. :-).
Although I admit it *was* stupid to comment the SQL assignment out. :-).