Discussion:
VBscript Class_Terminate --> JScript - How?
(too old to reply)
Harag
2003-12-29 10:48:42 UTC
Permalink
Hi all,

I'm currently learning javascript & Jscript

On the ASP server-side code I understand than when I create an object
I can emulate the "Class_Initialize" event in the object constuctor

But how do I do the Class_Terminate event in Jscript ? In vbscript I
would do

set oDBclass = nothing

and it would fire the following:

PRIVATE SUB Class_Terminate ()
' Close the connection Object and clear it
CloseDBConnection
set moConnection = nothing
END SUB

which closes the DB connections and frees up the resourses.

The only way I can think of in Jscript is to have a .Terminate
function

function Terminate(){
CloseDBConnection();
moConnection = null;
}

and use it like:

oDBclass.Terminate();
oDBclass = null;


Is this the right way of doing it? or is there a proper way?

Thanks for any help.

Al.
Chris Barber
2003-12-29 11:17:29 UTC
Permalink
Unless you are using ODBC then connection pooling would make reconnections
to the DB very fast (instantaneous almost) and in this instance you should
then create and destroy connections within each major function as opposed to
at the start and end of a Class. However, in ASP scenarios this is often a
little but of overkill and creating a connection at the start of a page
processing and destroying it at the end if often sufficient - indeed, for
ODBC (where connection pooling doesn't get activated) this is the best
method anyway.

In JS there is no concept of a terminate function because you can't
determine when the object will be destroyed (Garbage Collection) .Your
suggestion is probably the best method to use - an explicit call to a
function to clear up before releasing the object (setting it's reference to
null).

Of course server-side, the objects all get cleared up after the page
completes execution anyway so it's not *that* important to have a rock solid
clean-up system. However, within a page level it's always good practice to
destroy connections before the page completes executing just to make sure
you don't get any unwanted memory leaks from IIS (pretty rare these days).

Chris.

"Harag" <***@REMOVETHESECAPITALSsofthome.net> wrote in message news:***@4ax.com...

Hi all,

I'm currently learning javascript & Jscript

On the ASP server-side code I understand than when I create an object
I can emulate the "Class_Initialize" event in the object constuctor

But how do I do the Class_Terminate event in Jscript ? In vbscript I
would do

set oDBclass = nothing

and it would fire the following:

PRIVATE SUB Class_Terminate ()
' Close the connection Object and clear it
CloseDBConnection
set moConnection = nothing
END SUB

which closes the DB connections and frees up the resourses.

The only way I can think of in Jscript is to have a .Terminate
function

function Terminate(){
CloseDBConnection();
moConnection = null;
}

and use it like:

oDBclass.Terminate();
oDBclass = null;


Is this the right way of doing it? or is there a proper way?

Thanks for any help.

Al.
Harag
2003-12-29 12:14:17 UTC
Permalink
No I don't use ODBC. I use the following to connect to the MSSQL DB, I
bought the Developers edition when it dropped to £50 :)

Application("sDBConnection") = "Provider=SQLOLEDB; Data
Source=(local); Initial Catalog=DBName!; User ID=[***USER***];
Password=[***PASS***]; Persist Security Info=True"


The UserName & Password are replaced in my DB object so it can connect
to the DB with users.

I didn't know about "connection pooling" so in my class it connects up
the first time a SQL or Stored proc is executed then disconnects when
the class terminates. I generally do all my DB access at the top of
the ASP page and return them into arrays using ".GetRows" then the
rest of the ASP code uses the arrays for display tables etc.

Chris... The file I sent you is the class I use. (I know it might be
crap... it's my first effort at VBscript class) lol.




On Mon, 29 Dec 2003 11:17:29 -0000, "Chris Barber"
Post by Chris Barber
Unless you are using ODBC then connection pooling would make reconnections
to the DB very fast (instantaneous almost) and in this instance you should
then create and destroy connections within each major function as opposed to
at the start and end of a Class. However, in ASP scenarios this is often a
little but of overkill and creating a connection at the start of a page
processing and destroying it at the end if often sufficient - indeed, for
ODBC (where connection pooling doesn't get activated) this is the best
method anyway.
In JS there is no concept of a terminate function because you can't
determine when the object will be destroyed (Garbage Collection) .Your
suggestion is probably the best method to use - an explicit call to a
function to clear up before releasing the object (setting it's reference to
null).
Of course server-side, the objects all get cleared up after the page
completes execution anyway so it's not *that* important to have a rock solid
clean-up system. However, within a page level it's always good practice to
destroy connections before the page completes executing just to make sure
you don't get any unwanted memory leaks from IIS (pretty rare these days).
Chris.
Hi all,
I'm currently learning javascript & Jscript
On the ASP server-side code I understand than when I create an object
I can emulate the "Class_Initialize" event in the object constuctor
But how do I do the Class_Terminate event in Jscript ? In vbscript I
would do
set oDBclass = nothing
PRIVATE SUB Class_Terminate ()
' Close the connection Object and clear it
CloseDBConnection
set moConnection = nothing
END SUB
which closes the DB connections and frees up the resourses.
The only way I can think of in Jscript is to have a .Terminate
function
function Terminate(){
CloseDBConnection();
moConnection = null;
}
oDBclass.Terminate();
oDBclass = null;
Is this the right way of doing it? or is there a proper way?
Thanks for any help.
Al.
Chris Barber
2003-12-29 12:39:44 UTC
Permalink
Connection Pooling (VBScript examples only but apply equally to JScript):
http://www.sql-server-performance.com/bl_asp_ado.asp

Yikes, you're really making me question my own JScript experience and
coding - just been reading that article on private properties and methods.

Basically connection pooling says that for non-ODBC connections, when a
connection is closed it is returned to a pool so that when the next
connection *with an identical. connection string* is instantiated then it
will be retrieved form the pool as opposed to actually making the connection
from new. This process is near as dammit instantaneous and if understood and
used properly can increase your scaleability and performance a fair bit.
The basic premise here is that connections are *expensive* and as such
should be as short lived as possible. You should create a connection, use
the connection to do work, and then close it as soon as possible. When you
need it again it will already be in the pool, ready and waiting for use.

Chris.

"Harag" <***@REMOVETHESECAPITALSsofthome.net> wrote in message news:***@4ax.com...


No I don't use ODBC. I use the following to connect to the MSSQL DB, I
bought the Developers edition when it dropped to £50 :)

Application("sDBConnection") = "Provider=SQLOLEDB; Data
Source=(local); Initial Catalog=DBName!; User ID=[***USER***];
Password=[***PASS***]; Persist Security Info=True"


The UserName & Password are replaced in my DB object so it can connect
to the DB with users.

I didn't know about "connection pooling" so in my class it connects up
the first time a SQL or Stored proc is executed then disconnects when
the class terminates. I generally do all my DB access at the top of
the ASP page and return them into arrays using ".GetRows" then the
rest of the ASP code uses the arrays for display tables etc.

Chris... The file I sent you is the class I use. (I know it might be
crap... it's my first effort at VBscript class) lol.




On Mon, 29 Dec 2003 11:17:29 -0000, "Chris Barber"
Post by Chris Barber
Unless you are using ODBC then connection pooling would make reconnections
to the DB very fast (instantaneous almost) and in this instance you should
then create and destroy connections within each major function as opposed to
at the start and end of a Class. However, in ASP scenarios this is often a
little but of overkill and creating a connection at the start of a page
processing and destroying it at the end if often sufficient - indeed, for
ODBC (where connection pooling doesn't get activated) this is the best
method anyway.
In JS there is no concept of a terminate function because you can't
determine when the object will be destroyed (Garbage Collection) .Your
suggestion is probably the best method to use - an explicit call to a
function to clear up before releasing the object (setting it's reference to
null).
Of course server-side, the objects all get cleared up after the page
completes execution anyway so it's not *that* important to have a rock solid
clean-up system. However, within a page level it's always good practice to
destroy connections before the page completes executing just to make sure
you don't get any unwanted memory leaks from IIS (pretty rare these days).
Chris.
Hi all,
I'm currently learning javascript & Jscript
On the ASP server-side code I understand than when I create an object
I can emulate the "Class_Initialize" event in the object constuctor
But how do I do the Class_Terminate event in Jscript ? In vbscript I
would do
set oDBclass = nothing
PRIVATE SUB Class_Terminate ()
' Close the connection Object and clear it
CloseDBConnection
set moConnection = nothing
END SUB
which closes the DB connections and frees up the resourses.
The only way I can think of in Jscript is to have a .Terminate
function
function Terminate(){
CloseDBConnection();
moConnection = null;
}
oDBclass.Terminate();
oDBclass = null;
Is this the right way of doing it? or is there a proper way?
Thanks for any help.
Al.
Loading...