Closing objects correctly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TimSki
    New Member
    • Jan 2008
    • 83

    Closing objects correctly

    Hi,

    I believe this si the approved method for getting data out of a db in sql server ie. open connection, open obj, close obj, close connection

    openDataConnect ion()
    set rsID = CreateObject("A DODB.recordset" )
    rsID.Open " SELECT * from t_example, strConn
    set newObj = rsID
    rsID.close
    set rsID = nothing
    closeDataConnec tion()

    By setting rsID = nothing i believe i am freeing up webserver resources correctly.

    However, what happens to newObj, do i need to set that to nothing somewhere. If is is left open will the dataconnection have closed properly ?

    Thanks,

    Tim
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    Originally posted by TimSki
    Hi,

    I believe this si the approved method for getting data out of a db in sql server ie. open connection, open obj, close obj, close connection

    openDataConnect ion()
    set rsID = CreateObject("A DODB.recordset" )
    rsID.Open " SELECT * from t_example, strConn
    set newObj = rsID
    rsID.close
    set rsID = nothing
    closeDataConnec tion()

    By setting rsID = nothing i believe i am freeing up webserver resources correctly.

    However, what happens to newObj, do i need to set that to nothing somewhere. If is is left open will the dataconnection have closed properly ?

    Thanks,

    Tim
    As long as you close your record set and your connection which you have done you do not need to remove Objects from memory also.

    The only reason you would want to clear an object from memory is if you planned to re-use it on another page, or process where it may be re-populated or re-dimmed to hold new data.

    In fact the beauty of the objects is that you can open your connection, your RS, populate your object, then close your RS and connection, then from that point forward you only need to work with the object instead of constantly connecting to the DB over and over.

    Comment

    • TimSki
      New Member
      • Jan 2008
      • 83

      #3
      great, many thanks for clarifying this for me.

      Comment

      Working...