|
 |
asp_discuss thread: Close A Connection
Message #1 by rg1@h... on Wed, 22 Aug 2001 23:03:25
|
|
Hi.
I know it's good practice to always close what's been opened and set an
object to nothing.
I have a concern over the way I've coded my Data Access Layer.
I'm using VBScript and in my DAL have a Private Function GetConnection and
a Public Function GetRecords. In my ASP page I "Set rs = GetRecords" from
the DAL to return rows from a SQL database.
In GetRecords, I open a connection, get my recordset and return the
recordset.
All good and well - I'm getting all the information I need. However, in
GetConnection, when I'm done I set the connection to nothing. I had closed
the connection but then got an error message when I tried to refenence the
returned rs in my ASP page. Once I took out the con.Close statement,
everything was ok.
My concern is that I now have a connection open that I can't close as I'm
out of the coding that opened it.
How can I make my coding more efficient?
TIA.
Rita
Message #2 by Hal Levy <hal.levy@s...> on Fri, 24 Aug 2001 10:42:34 -0400
|
|
This is expected behaviour. The recordset (assuming your using defaults)
only exists when the connection is open.
You can use a number of solutions:
1. Use a Client Side Recordset.
2. Use .getrows() to move the data from a recordset to a multi-dimensional
array.
Perhaps someone else can give you further information on the performance
benefits of each- I prefer to use .getrows()
Hal Levy
StarMedia Network, Inc.
Intranet Development Manager
> -----Original Message-----
> From: rg1@h... [mailto:rg1@h...]
> Sent: Wednesday, August 22, 2001 7:03 PM
> To: asp_discuss
> Subject: [asp_discuss] Close A Connection
>
>
> Hi.
>
> I know it's good practice to always close what's been opened
> and set an
> object to nothing.
>
> I have a concern over the way I've coded my Data Access Layer.
>
> I'm using VBScript and in my DAL have a Private Function
> GetConnection and
> a Public Function GetRecords. In my ASP page I "Set rs =
> GetRecords" from
> the DAL to return rows from a SQL database.
>
> In GetRecords, I open a connection, get my recordset and return the
> recordset.
>
> All good and well - I'm getting all the information I need.
> However, in
> GetConnection, when I'm done I set the connection to nothing.
> I had closed
> the connection but then got an error message when I tried to
> refenence the
> returned rs in my ASP page. Once I took out the con.Close statement,
> everything was ok.
>
> My concern is that I now have a connection open that I can't
> close as I'm
> out of the coding that opened it.
>
> How can I make my coding more efficient?
>
> TIA.
>
> Rita
|
|
 |