
|
A Best Practice for Using ADO Objects By 15 Seconds Discussion List |
Rating: 2.8 out of 5 Rate this article
|
email this article to a colleague
suggest an article
|
Don Asks:
When you create a variable in your ASP page and assign a string value of "hello" to it, should any clean up of this variable take place, or does this happen automatically when the ASP page is finished parsing?
David:
For all variables, this is true. BUT, for objects, if you do not SET them to Nothing, you will have memory leaks. Of course, if there is a .Open method, you should close it as well *before* setting it to nothing.
Tore:
If a recordset is not open or does not exist, attempting to close it will cause an error. In some cases (for example creating a recordset from a connection.Execute with no result rows returned) the recordset is not actually created.
However, there is nothing magic about a .Open method. It is just a method provided by the developer of an object. Usually, if the object was created by a programmer worth anything, an object that has an "Open" method should have a "Close" method (for explicit housekeeping). And the Class_Terminate event should check whether the user actually performed the Close, and if not, perform one implicitly. However, the more complex an object becomes, the more difficult this is to ensure. In some cases it may not even be possible. Other method pairs may exist for certain objects, and they may be called whatever the developer found meaningful at the time of implementation - Reserve/Release, Edit/Update[|Cancel], Start/Stop, etc.
It is an accepted "best practice" to always explicitly close and dereference objects. The following construct is safe for most ADO objects:
If Not adoObjSomething Is Nothing Then
If adoObjSomething.State = adStateOpen Then
adoObjSomething.Close
End If
Set adoObjSomething = Nothing
End If
This conversation string was taken from the 15Seconds ASP Listserv on 3/26/02. If you have an ASP-related question or would like to share some of your knowledge with others, you may join the list by clicking here.
|
|
|
|
|
Supporting Products/Tools
|
|
Proposion N2N
|
|
Proposion N2N connects Microsoft .NET applications to Lotus Notes and Lotus Domino databases. This ADO.NET managed data provider allows you to perform blindingly fast queries and updates of Notes data from ASP.NET pages, .NET web services, Windows, or Mobile applications. An innovative SQL-like query language leverages the unique features of Notes and makes collaborative software accessible to relational database programmers.
|
[Top]
|
|
|
|
Other Articles
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sep 11, 2001 - Randomizing a Recordset
|
|
|
Ed Myers' article shows several ways to use a SQL calculated field and the ORDER BY clause to arrange a recordset in random order. A simple tool is provided for verifying that the results are uniformly random. A technique for bubbling records with certain attributes to the top of an otherwise randomized list is also shown.
[Read This Article] [Top]
|
|
|
Mailing List
Want to receive email when the next article is published? Just Click Here to sign up.
|
|