Closing Recordsets/Connections

Discussion in 'ASP General' started by CJM, Jan 31, 2006.

  1. CJM

    CJM Guest

    Is it sufficient to Set a Connection or Recordset to Nothing, or ought they
    specifically be closed first?

    E.g.

    Set rs = oConn.Execute(sSQL)

    'Do stuff

    Set rs = Nothing
    Set oConn = Nothing




    --

    [remove the obvious bits]
     
    CJM, Jan 31, 2006
    #1
    1. Advertising

  2. CJM

    CPrice79 Guest

    I would explicitly call close on both the rs and conn objects.

    Example:
    if IsObject(rs) then
    if not rs is Nothing Then
    if rs.state <> 0 then
    rs.close
    end if
    end if
    end if

    "CJM" wrote:

    > Is it sufficient to Set a Connection or Recordset to Nothing, or ought they
    > specifically be closed first?
    >
    > E.g.
    >
    > Set rs = oConn.Execute(sSQL)
    >
    > 'Do stuff
    >
    > Set rs = Nothing
    > Set oConn = Nothing
    >
    >
    >
    >
    > --
    >
    > [remove the obvious bits]
    >
    >
    >
     
    CPrice79, Jan 31, 2006
    #2
    1. Advertising

  3. Hello CJM

    I agree with CPrice here. It is better to close it directly instead of just
    setting it to nothing. There are some network connection opened when using
    RS and Connection object. Using close method can close the network
    connection and clean the resource.

    Thanks.

    Best regards,
    Yanhong Huang
    Microsoft Community Support

    Get Secure! ┬ĘC www.microsoft.com/security
    Register to Access MSDN Managed Newsgroups!
    http://msdn.microsoft.com/subscriptions/managednewsgroups/

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Yan-Hong Huang[MSFT], Feb 1, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Do
    Replies:
    2
    Views:
    367
    srinivas moorthy
    Dec 9, 2003
  2. Patrice
    Replies:
    3
    Views:
    7,129
    Michael D. Long
    Sep 22, 2004
  3. Michael D. Long

    Re: Opening / Closing SQL Server connections

    Michael D. Long, Sep 22, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    489
    Michael D. Long
    Sep 24, 2004
  4. jobs
    Replies:
    2
    Views:
    899
  5. James

    Closing Recordsets

    James, Oct 29, 2004, in forum: ASP General
    Replies:
    4
    Views:
    127
    Bob Barrows [MVP]
    Oct 29, 2004
Loading...

Share This Page