
Is there an event fired inside a script component when it is destroyed, like VB's Class_Terminate?
Sorry Vince, completly missed your response to my last post.
It doesn't really matter - once the object reference goes out of scope (eg.
a private variable at the exit point of a function) it wil be destroyed
anyway as a matter of course. However, it's not really good practice to
*depend* on this. There are circumstances when this could fail (generally
badly designed dll's for example).
In your case, I wouldn't worry.
Still, you should try to encapsulate all you ADO stuff into functions and
methods that explicitly create and destroy the object as they enter and
exit. That's the holy grail.
Chris Barber.
Chris, I read at http://www.15seconds.com/issue/970531.htm that ODBC
supports connection pooling since version 3.0. However I didn't think of it.
But The reason I was about to wrap ADO objects was to find a work around to
not closing and assigning ADO components to nothing at the end of a script.
ADO recordsets and connections must be explicitly closed otherwise
"problems" may occur.
But now I think I understand a bit more those problems. However I'd like to
know if the effect of not assigning recordset variables to nothing is the
same as with connections. Does it really hurt when I don't "Set rs =
Nothing" after "rs.Close" and what is its impact?
Thanks.
--
Vince C.
Quote:
> Doesn't connection pooling completely negate the overhead by allowing you
to
> reuse an existing connection without the connection having to be
> re-established?
> [Unless its a DSN because I believe that ODBC doesn't support pooling?]
> Chris Barber.
> > Thanks, Michael and Alex. I was asking that question because I wanted to
> > know how to use ADO in script components. If there were some kind of a
> > "Terminate" event, I could have created a connection at startup, for
> > instance, and close/free it upon destruction (ADO objects require to be
> > closed and freed explicitly in ASP to avoid troubles).
> > Now two options: either using Michael's hack (and allocate/free ADO's
> object
> > in the internal Class, maybe) or create/open/close/free the ADO object
in
> > each script component's method in which ADO is involved. I think the
> latter
> > will lead to performance issues because of the overhead.
> > Anyway it's good to know.
> > Thanks again.
> > --
> > Vince C.
> > WSCs don't support the equivalent of the VB/VBA/VBScript class
> > Class_Initialize/Terminate handlers. A *hack* is to create a private
> > vbscript class instance within the WSC when the WSC is first created.
> > The vbscript class implements only the Class_Terminate handler. All it
> does
> > is serve as a proxy to call a private clean up method within the WSC.
> When
> > the WSC goes out of scope and is being torn down, so is the internal
> > vbscript class instance, which fires the instance's Class_Terminate
> handler
> > which calls the WSC's clean up method...
> > --
> > Michael Harris
> > Microsoft.MVP.Scripting
> > Seattle WA US
> > --
> > > Thank you Alex.
> > > I already have the documentation however but I didn't find anything on
> > > termination events. I know about VBScript's support for Class but what
> I'd
> > > like to know is about script components (those which are defined in
WSC,
> > > XML-Compliant files). The script code that lies in the CDATA section
can
> > be
> > > launched when a component is created but I couldn't figure out how
(and
> > > simply: if) I could execute code upon destruction.
> > > --
> > > Vince C.
> > > "Alex K. Angelopoulos" <alex_angelopoulos_at_hotmail_dot_com_remove__>
> > wrote
> > > LOL- :)
> > > You *really* want the documentation.
> > > My apologies, by the way - I directed you to the pure US-English docs.
> If
> > > you prefer, I *think* the following location - which has localized
> > versions
> > > of WSH - may have documentation localized for LCIDs other than 1033; I
> did
> > > see both French and Dutch versions of WSH there...
> > > Watch for URL wrap, this will be long -
http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...
Quote:
> > > sdncompositedoc.xml
> > > ================================
> > > Here's another one from the docs -
> > > Terminate Event
> > > Applies To: Class Object
> > > Occurs when an instance of the associated class is terminated.
> > > Private Sub Class_Terminate()
> > > statements
> > > End Sub
> > > The statements part consists of zero or more code statements to be run
> > when
> > > the class is initialized.
> > > Remarks
> > > The following example illustrates the use of the Terminate event.
> > > Class TestClass
> > > Private Sub Class_Initialize ' Setup Initialize event.
> > > MsgBox("TestClass started")
> > > End Sub
> > > Private Sub Class_Terminate ' Setup Terminate event.
> > > MsgBox("TestClass terminated")
> > > End Sub
> > > End Class
> > > Set X = New TestClass ' Create an instance of TestClass.
> > > Set X = Nothing ' Destroy the instance.
> > > : Thanks.
> > > :
> > > : --
> > > :
> > > : Vince C.
> > > :
> > > :
> > > :
> > > :
> > > :
> > > :