Link to home
Start Free TrialLog in
Avatar of Sirable
Sirable

asked on

How can i make sure that TADOQueries that run asynchronously wait for each other.

Hello All,

This is my first article/question that i will be posting.

I have several questions and issues. I will try to be clear.

I am using delphi 2007 (RAD).

Background: I have an application where i have 4 TADOQueries (lets say A, B, C and D) running asynchronously with ExecuteOptions (eoAsyncExecute, eoAsyncFetchNonblocking). With cursor location 'clUseClient' and cursortype 'ctKeySet.'

My Application connects to a Database on a server, and eacht time executes the 4 queries to get the latest information to store in Objects (these data is not shown in Datagrids or something similar).

The data is receive from query A and B are needed together to perform some calculations, and the same goes for query C and D.

1. How can i make sure that query A and B wait for each other before continuing as they are executed asynchronously. (The solution i have now is to make use of the OnFetchComplete of query A that triggers the execution of Query B. But is there some other way?)

2. I do not use a TDataset. I only have a TADOConnection and a TADOQuery. Is it better/faster/more stable to use TDataSets to store the information from the TADOQuery?

3. When i close the application i get sometimes get error messages: probabaly because some queries are still running. How can i make sure that the query-thread is terminated immediately? I have tried:

[ if TADOQuery.Active
  begin
  TADOQuery.First;
  TADOQuery.Close;
  end;
]

4. Is there a smarter way to update the data then performing the 4 queries continously?

5. I have a strange issue: when query A and B are performed the first time when the application starts they result in lets say 200 records each. But the second time and each time after they are performed they result in 0 records.

6.Another strange issue: when i tested the ADOquery separately (whether its A, B, C or D)  the execution time was around 1 a 2 seconds each time i executed it. When i perform them together the execution time sometimes goes up to 30 seconds total.

Well i hope i was clear and that i haves asked too many question in 1 run.

Thanks in advance,

Sirable
Avatar of 2266180
2266180
Flag of United States of America image

>> The solution i have now is to make use of the OnFetchComplete of query A that triggers the execution of Query B. But is there some other way?

this is the best way in your conditions. the other would be to not make them async, but sync. that is what I would use, unless the query takes too long. even so, you could use sync and just place the query execution in a separate thread.

>> Is it better/faster/more stable to use TDataSets to store the information from the TADOQuery?
TAdoQuery is a TDataSet descendant :) meaning you are already using a TDataSet

>> How can i make sure that the query-thread is terminated immediately?
I never used async, but when the objects get destroy, the connections get closed as well. this is no matte rif it is async or not. so, the quesiton is: what error message did you get?

>> Is there a smarter way to update the data then performing the 4 queries continously?
that depends on the data. how often is it being updated in the db? if it is many times more rarely than you update from your application, then you can use a flag either in your tables or in anotehr table to notify when the data was modified. and then only query for that flag continuosly.
 you can use triggers to update that flag, so no code is written in the app that updates the data

>. But the second time and each time after they are performed they result in 0 records.
this can be normal depending you your query and when the data is being updated. are you saying that "each time after" they return 0? meaning that they do not return more than 0 ever? until you restart the app? we cannot guess what is tehre so post the query and explain the data and how and when it is updated you might want to consider opening a second question for this issue


>> Another strange issue: when i tested the ADOquery separately (whether its A, B, C or D)  the execution time was around 1 a 2 seconds each time i executed it. When i perform them together the execution time sometimes goes up to 30 seconds total.

again: it depends on the query and data. more info needed.
Avatar of Sirable
Sirable

ASKER

Hello Ciuly,

Thanks for your feedback :).

The data is updated every second in the database. It is realtime info. And i use that information for my application.

I have found the reason why i keep getting 0 records. Because the Filter was still set to True.


This is the error message i (sometimes) get when closing the application:

"Exception EOleException in module 'Name.exe' at 'address'. Operation cannot be performed while executing asynchronously"

thanks,

Sirable
Avatar of Sirable

ASKER

Hello Ciuly,

Thanks for your feedback :).

The data is updated every second in the database. It is realtime info. And i use that information for my application.

I have found the reason why i keep getting 0 records. Because the Filter was still set to True.


This is the error message i (sometimes) get when closing the application:

"Exception EOleException in module 'Name.exe' at 'address'. Operation cannot be performed while executing asynchronously"

thanks,

Sirable
Avatar of Sirable

ASKER

Hello Ciuly,

Thanks for your feedback :).

The data is updated every second in the database. It is realtime info. And i use that information for my application.

I have found the reason why i keep getting 0 records. Because the Filter was still set to True.


This is the error message i (sometimes) get when closing the application:

"Exception EOleException in module 'Name.exe' at 'address'. Operation cannot be performed while executing asynchronously"

thanks,

Sirable
ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sirable

ASKER

Hello Ciuly,

Thanks for your help :). It proved wonderfully.

Good luck in the future