Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 28th, 2004, 06:33 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Scope of recordset variables

Hi,

I have some general functions in an ASP include file. One of them is:

------------------------------------------------------
Function GetTable(tablename)

    Dim d
    Dim strSQL

    strSQL = "SELECT * FROM " & tablename

    Set d = Server.CreateObject("ADODB.RecordSet")
    rsData.Open strSQL, dcnDB, adOpenStatic, adLockReadOnly

    Set GetTable = d

End Function
------------------------------------------------------


In my main page, I do this:

' Declare recordset variable
Dim rsData

' Call function
Set rsData = GetTable("Clients")

< code to read and display the records etc...>

' Cleanup
rsData.Close
Set rsData = nothing


Question:

I do the cleanup on the main page (to close the recordset). However, there is no cleanup in the function for the local d variable. I can't cleanup that because if I do, I cannot pass the contents of it back in the statement Set GetTable = d.

Does d cleanup automatically by virtue of going out of scope (because it is a local variable in the function)? Or do I end up with the recordset object d floating around on the server because I have not cleaned it up?

Please teach me about this area... cleanups / scoping / persistence of objects / how a recordset is "passed" from the function to my main page, etc.

Thanks.

James

//##



  #2 (permalink)  
Old January 28th, 2004, 09:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I'm not as knowledgable as some of the other individuals that post to this site, but what I usually did is this:
Code:
Set GetTable = d
set d = nothing
I know in the .NET world, the garbage collector automatically recycles unused variables for you, but I think in the ASP/VB6 world, you have to do it. I know VB6 you should set your variables to nothing; otherwise, resources will still be open (I had a problem with, when accessing the Word API's, the Word.exe file would never close, and I would be left with 50 instances!).

I'm not sure how crucial it is in ASP; personally, I make a note of it to always set my variables to nothing in the end, even in my .NET development.

Hope this helps,

Brian
  #3 (permalink)  
Old January 28th, 2004, 09:37 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Brian.

Can someone give me a second opinion on this issue, please?

James



Similar Threads
Thread Thread Starter Forum Replies Last Post
Scope Issue iceman90289 C# 2005 8 April 5th, 2008 03:41 PM
scope of variables in VB.NET bhavna General .NET 1 January 26th, 2007 06:00 PM
the scope of variable ccj_999 C++ Programming 9 October 26th, 2006 10:35 AM
Javascript Scope of Variables. minhtam Javascript 2 January 7th, 2006 10:27 PM
"Recordset Scope" Nitin_sharma Classic ASP Databases 5 September 23rd, 2004 05:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.