ending a sub and closeing database

ending a sub and closeing database

Post by Mike Malon » Wed, 28 Aug 2002 13:46:55



When do I need to close a database or a recordset when
exiting a function.

I would think that by exiting the sub that the recordset
would go out of scope and be destroyed with the system
providing garbage cleanup.

What about the database object?

I can't find a way to tell if a database object is open
and created so that I can put a generic close at the end
of my sub or do I evan need to? Will it just close on
loseing scope?

- Mike

 
 
 

ending a sub and closeing database

Post by Marily » Wed, 28 Aug 2002 14:17:11


Exiting the sub destroys the recordset _reference_ ; that's not the same as
telling the database that the recordset isn't needed anymore; similarly the
database needs to be told that it's not wanted anymore, so it can do it's
own cleaning up. In particular, if your recordset was created from a query
the database may have created a hidden temporary table ... if you don't
close the recordset, the temporary table won't be deleted and your database
will grooooow.

Rather than worry about whether it's still open, close it anyway and ignore
any error

On error resume next
rs.close
set rs = nothing
db.close
set db = nothing
err.clear
Exit sub


Quote:> When do I need to close a database or a recordset when
> exiting a function.

> I would think that by exiting the sub that the recordset
> would go out of scope and be destroyed with the system
> providing garbage cleanup.

> What about the database object?

> I can't find a way to tell if a database object is open
> and created so that I can put a generic close at the end
> of my sub or do I evan need to? Will it just close on
> loseing scope?

> - Mike


 
 
 

ending a sub and closeing database

Post by mike malon » Thu, 29 Aug 2002 01:47:30


thanks

Quote:>-----Original Message-----
>Exiting the sub destroys the recordset _reference_ ;

that's not the same as
Quote:>telling the database that the recordset isn't needed

anymore; similarly the
Quote:>database needs to be told that it's not wanted anymore,
so it can do it's
>own cleaning up. In particular, if your recordset was

created from a query
Quote:>the database may have created a hidden temporary

table ... if you don't
>close the recordset, the temporary table won't be deleted
and your database
>will grooooow.

>Rather than worry about whether it's still open, close it
anyway and ignore
>any error

>On error resume next
>rs.close
>set rs = nothing
>db.close
>set db = nothing
>err.clear
>Exit sub



>> When do I need to close a database or a recordset when
>> exiting a function.

>> I would think that by exiting the sub that the recordset
>> would go out of scope and be destroyed with the system
>> providing garbage cleanup.

>> What about the database object?

>> I can't find a way to tell if a database object is open
>> and created so that I can put a generic close at the end
>> of my sub or do I evan need to? Will it just close on
>> loseing scope?

>> - Mike

>.

 
 
 

1. Type, sub-type, and sub-sub-type database design

I am trying to figure out the best way to design part of a database that
includes a type of material, a sub-type of that material, and a sub-type of
the sub-type of material.  For example one type of material is Hardwood,
which could have Oak as a sub-type, which could then have Red Oak, White
Oak, etc. as sub-types of the subtype.  I am struggling to figure out the
best way to go about this.

The way it will be used is through a web interface where users will first
select the main material type and based on that selection will then select
the sub-material type and then finally the detailed material type.

One option would be to have a Material table and then for each material
have a Sub-Material table, i.e. Sub-Hardwood, Sub-Softwood, etc.  This
wouldn't be bad at two levels but because of the third level requirements,
I could end up needed hundreds of tables to describe each material.  This
seems to be way too massive and a maintenance nightmare.

Other than that I am at a lose as to a simple solution to this problem.  I
am sure this has been done many times as I have seen applications like this
on the Internet before.  Anybody have any ideas on easy way to go about
this?

Thank you for any responses,
Jeremy Olmstead

2. What is the ISQL tool?

3. Master Parts/Sub Parts/Sub-Sub Parts

4. v$session - counting concurrent users, etc.

5. logging start and end times for sub-procedures

6. Database compatiibility from 11.03 to 11.5....

7. How to stop a sub command with out ending application

8. Help Wanted: FPW2.6->VFP/SQL Server & VFP/Word/HTML - D.C. Area

9. Sub queries <> sub tablesl

10. Query using UDF joined to a sub query vs Temp Table to sub Query

11. How do I implement sub sub filters ??

12. Pick Archive - PAR.SUB source code - par.sub (1/1)

13. Pick Archive - PAR.SUB source code - par.sub (0/1)