Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADOQueries - When to close?

Status
Not open for further replies.

AP81

Programmer
Apr 11, 2003
740
AU
A quick question.

I have a number of ADOQueries being used in my program. Should I close them and open them each time a query is executed or leave them open and close them all on exit?

Thanks.




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
Depends on the size of the data extracted in each query.

I tend to close my sub-queries when not required (even though they are quite small, but there are quite a few), but the navigational query is a list of names that open new queries when selected, and this is left open.

However, I still apply the old rule of minimising memory use - so close the unneeded queries, especially if they are large.

I'm sure some of our colleagues in this group have more detail about memory use with ADO queries.

Hope that helps.....

Chris ;-)
 
Thanks ChrisGSchultz,

I have a similar approach to yours, I just wanted an opinion and some reassurance I had the riht approach. I tend to close a query based on two factors:

1. size of dataset
2. frequency of use

One last question, does it use up more memory if you dynamically create the query each time it is run, e.g.

TestQuery := TADOQuery.create(nil);
TestQuery.ConnectionString := ...
...

Thanks




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
I would close the queries when you close the form. Seems tidiest and most sensible.

I would have thought creating a query on the fly is bound to use more resourses, but I doubt whether it is significant.The key thing would be to make sure you always Destroy it when you have finished with it.

Personally, when I want to set up an ADOquery on the fly, I create one in my datamodule module with a Connection string etc already set up, then set the SQL and run the query as required. For example:

with dmRegistrations.quGeneral do begin
if active then close;
SQL.clear;
SQL.Add('SELECT Category from luCategory where categorytype = "C" order by category');
open;
// etc
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top