View Single Post
  #1 (permalink)  
Old January 28th, 2004, 06:33 AM
James Diamond James Diamond is offline
Authorized User
Join Date: Jan 2004
Location: , , .
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Scope of recordset variables


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
Set rsData = nothing


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.