|
 |
asp_web_howto thread: using include file for database connection
Message #1 by williams@s... on Thu, 13 Sep 2001 11:53:05 -0400
|
|
Hi,
Throughout my intranet web site, I have been using the suggested include
file (datastore.asp in wrox Active Server Page 3.0 ISBN1-861003-38-2) for
my database connection . In the book , I don't see explicit close and set
to nothing of connection as other RS object.
I think it is not necessary, please correct me if I am wrong, because
connection object is not created. So let the "ADO to handle the connection
under the covers" (quote from the book) is no harm on the performance at
all?
Thanks
William
Message #2 by "Ken Schaefer" <ken@a...> on Fri, 14 Sep 2001 15:59:39 +1000
|
|
You should always clean up after yourself - that is good programming
practise. As well, you should dispose of objects as soon as you don't need
them - especially DB connections, since they are then returned to the
OLEDB/ODBC connection pool, rather than waiting until your whole page has
executed.
Have a routine that returns an open connection. Have another routine that
disposes of objects.
<%
Sub objDispose( _
objToDispose, _
blnCloseObject, _
blnSetToNothing _
)
If isObject(objToDispose) then
If blnCloseObject then objToDispose.Close
If blnSetToNothing then Set objToDispose = Nothing
End If
End Sub
'
'
Call objDispose(objConn, True, True)
%>
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: <williams@s...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Friday, September 14, 2001 1:53 AM
Subject: [asp_web_howto] using include file for database connection
: Hi,
:
: Throughout my intranet web site, I have been using the suggested include
: file (datastore.asp in wrox Active Server Page 3.0 ISBN1-861003-38-2) for
: my database connection . In the book , I don't see explicit close and set
: to nothing of connection as other RS object.
:
: I think it is not necessary, please correct me if I am wrong, because
: connection object is not created. So let the "ADO to handle the connection
: under the covers" (quote from the book) is no harm on the performance at
: all?
:
: Thanks
: William
Message #3 by "Scott Dempsey" <scottd@p...> on Thu, 13 Sep 2001 23:04:08 -0700
|
|
Nicely put, Ken.
It's late. Go to bed.
-----Original Message-----
From: Ken Schaefer [mailto:ken@a...]
Sent: Thursday, September 13, 2001 11:00 PM
To: ASP Web HowTo
Subject: [asp_web_howto] Re: using include file for database connection
You should always clean up after yourself - that is good programming
practise. As well, you should dispose of objects as soon as you don't need
them - especially DB connections, since they are then returned to the
OLEDB/ODBC connection pool, rather than waiting until your whole page has
executed.
Have a routine that returns an open connection. Have another routine that
disposes of objects.
<%
Sub objDispose( _
objToDispose, _
blnCloseObject, _
blnSetToNothing _
)
If isObject(objToDispose) then
If blnCloseObject then objToDispose.Close
If blnSetToNothing then Set objToDispose = Nothing
End If
End Sub
'
'
Call objDispose(objConn, True, True)
%>
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: <williams@s...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Friday, September 14, 2001 1:53 AM
Subject: [asp_web_howto] using include file for database connection
: Hi,
:
: Throughout my intranet web site, I have been using the suggested include
: file (datastore.asp in wrox Active Server Page 3.0 ISBN1-861003-38-2) for
: my database connection . In the book , I don't see explicit close and set
: to nothing of connection as other RS object.
:
: I think it is not necessary, please correct me if I am wrong, because
: connection object is not created. So let the "ADO to handle the connection
: under the covers" (quote from the book) is no harm on the performance at
: all?
:
: Thanks
: William
Message #4 by williams@s... on Fri, 14 Sep 2001 10:32:01 -0400
|
|
Ken,
Thanks .
But I do not create objConn connect object explicitly in my ASP. The coding
is:
<!--#include file="connect.asp"-->
<% Dim strConn
:
:
objRS1.open strConn
:
:
objRS2.open strConn
:
:
objRS3.open strConn
:
:
objRS1.close
set objRS1 = nothing
objRS2.close
set objRS2 = nothing
objRS3.close
set objRS3 = nothing
%>
It is working fine in most of my users(they have their own sql server and
IIS server), but for one user, he experiences slow response. So I wonder it
may due to not closing the connecting explicitly. But on the other hand, I
don't have explicit connect object to close.
Please advise.
Thanks
william
"Ken Schaefer"
<ken@a... To: "ASP Web HowTo" <asp_web_howto@p...>
tic.com> cc:
Subject: [asp_web_howto] Re: using include file for database
09/14/2001 connection
01:59 AM
Please respond
to "ASP Web
HowTo"
You should always clean up after yourself - that is good programming
practise. As well, you should dispose of objects as soon as you don't need
them - especially DB connections, since they are then returned to the
OLEDB/ODBC connection pool, rather than waiting until your whole page has
executed.
Have a routine that returns an open connection. Have another routine that
disposes of objects.
<%
Sub objDispose( _
objToDispose, _
blnCloseObject, _
blnSetToNothing _
)
If isObject(objToDispose) then
If blnCloseObject then objToDispose.Close
If blnSetToNothing then Set objToDispose = Nothing
End If
End Sub
'
'
Call objDispose(objConn, True, True)
%>
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: <williams@s...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Friday, September 14, 2001 1:53 AM
Subject: [asp_web_howto] using include file for database connection
: Hi,
:
: Throughout my intranet web site, I have been using the suggested include
: file (datastore.asp in wrox Active Server Page 3.0 ISBN1-861003-38-2) for
: my database connection . In the book , I don't see explicit close and set
: to nothing of connection as other RS object.
:
: I think it is not necessary, please correct me if I am wrong, because
: connection object is not created. So let the "ADO to handle the
connection
: under the covers" (quote from the book) is no harm on the performance at
: all?
:
: Thanks
: William
Message #5 by "Ken Schaefer" <ken@a...> on Mon, 17 Sep 2001 15:17:39 +1000
|
|
This is a bad way to write code. You are implicitly creating *3* connection
objects, even though you only need one. As well, the connections are not
returned to the connection pool until the page has finished processing:
See:
http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q191572
and
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmdac/html
/pooling2.asp
You should:
1) Explicitly create and open a connection object
2) Do your recordset work, passing the connection object to the Recordset's
.Open method
3) [Optional] Get each recordset into an array, and dispose of recordset
object
4) Dispose of recordset objects
5) Dispose of connection object
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <williams@s...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Saturday, September 15, 2001 12:32 AM
Subject: [asp_web_howto] Re: using include file for database connection
: Ken,
:
: Thanks .
:
: But I do not create objConn connect object explicitly in my ASP. The
coding
: is:
:
: <!--#include file="connect.asp"-->
: <% Dim strConn
: :
: :
: objRS1.open strConn
: :
: :
: objRS2.open strConn
: :
: :
: objRS3.open strConn
: :
: :
: objRS1.close
: set objRS1 = nothing
: objRS2.close
: set objRS2 = nothing
: objRS3.close
: set objRS3 = nothing
: %>
:
: It is working fine in most of my users(they have their own sql server and
: IIS server), but for one user, he experiences slow response. So I wonder
it
: may due to not closing the connecting explicitly. But on the other hand, I
: don't have explicit connect object to close.
:
: Please advise.
:
: Thanks
: william
:
.com
|
|
 |