[thelist] conserving resources - closing a recordset in ASP

Ken Schaefer ken at adOpenStatic.com
Mon Sep 22 20:44:37 CDT 2003


Look up using .GetRows()

Moves your Recordset into a local array variable. Then you can dispose of
your recordset object -and- your connection object, and return the array
instead.

Having recordsets floating around isn't the big problem. Eventually they'll
be garbage collected. The big problem is having *connection* objects
floating around. Databases don't scale well w.r.t. to the number of physical
connections that they can handle. Even big industrial DBMS might be able to
handle 500 physical connections. To support large numbers of users you need
to use some kind of connection pooling system. So that the database thinks
it has only 500 connections, but these are being shared between thousands,
or tens of thousands of users.

To use pooling effectively, you need to return connections to the pool. For
an ASP/ADO overview, check out:

INFO: Connection Pool Management by ADO Objects Called From ASP
http://support.microsoft.com/?id=191572

    -and-

Pooling in the Microsoft Data Access Components
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmdac/html/pooling2.asp

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Sarah Sweeney" <ssweeney at w3internet.com>
Subject: [thelist] conserving resources - closing a recordset in ASP


: 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.
: So, if I were to do something like:
:    var contents = doQuery('SELECT Title FROM Content');
:    while (!contents.EOF)
:    {
:      Response.Write(contents('Title') + '<br />');
:      contents.MoveNext;
:    }
:    contents.Close;
:    contents = null;
: Is "contents.Close;" actually closing the original recordset, or just a
: copy? If it's only closing a copy, is there any way to get around this,
: without having to scrap my doQuery() function altogether?
:
: TIA



More information about the thelist mailing list