A gift: comprehensive ADO mgmt in a class

antic

Perch
Hi all,

Here is some code I developed, which facilitates management of ADO objects in ASP.

The main benefit is that it completely eliminates the problem of left-over connections & recordsets that never get closed. This is of benefit to the developer and also to the hosting provider.

Even if you end your code with Response.End, or even if the code crashes (depending on the severity), all recordsets and connections that have been opened with this class will be neatly closed and related ADO objects destroyed.

This has always been a problem with ADO in ASP, but using this class it is a problem no longer. I've used it for many months (and a previous version for a couple of years) and it's proven to work well.

Examine the demo code file for examples on use.

Hope it's useful to someone. Comments welcome.
 

Attachments

  • clsADO.zip
    3.6 KB · Views: 51
One useful minor alteration to the class, is to take the code out of Class_Terminate() and put it in it's own method, called CloseConnection(). Class_Terminate() can then simply contain Call CloseConnection.

This gives more control over exactly when the recordset & connection objects get destroyed, as I believe the ASP runtime doesn't always destroy objects at the exact time the script ends; it sometimes happens a little after, during garbage collection. I know ASP.NET has that behaviour, which is by design.

So optionally, you can add one extra line before a Response.End as so:
Code:
ezConn.CloseConnection
Response.End
It's entirely optional, but gives you the freedom to ensure that all db objects are destroyed at the time your script ends. It's especially useful if you're using LockPessimistic somewhere (which you'd rarely do anyway) so you know for sure you've unlocked all your locks.
 
Looks good, and it seems the download counter does not work, still saying 0 when I know I downloaded it.
 
Back
Top