[thelist] conserving resources - closing a recordset in ASP

Wade Armstrong wade at wadearmstrong.com
Mon Sep 22 13:22:07 CDT 2003


On 9/22/03 Sarah Sweeney <ssweeney at w3internet.com> wrote:

>I am trying to make my ASP code a little easier to write, and read, by 
>creating a function to perform a query for me and return a recordset. 
>Here 
>is the function:
>   function doQuery(sql)
>   {
>     var rs = Server.CreateObject("ADODB.Recordset");
>     rs.Open(sql,conn,adOpenStatic);
>     return rs;
>   }
>Of course, using this function means that the recordset doesn't get 
>closed. 

How about:

  function doQuery(sql)
  {
    var rs = Server.CreateObject("ADODB.Recordset");
    rs.Open(sql,conn,adOpenStatic);
    var myArr = rs.GetRows()
    rs.Close
    rs = null
    return myArr;
  }
  
That will leave you with a nice, handy two-dimensional array of your
query results, through which you can iterate without having to carry an
object around.

Wade 


More information about the thelist mailing list