Is it necessary to close an Adodb.recordset object before setting it to nothing?

后端 未结 4 1453
猫巷女王i
猫巷女王i 2021-02-13 19:05
Dim rs as ADODB.Recordset
set rs = ReturnARecordset \'assume ReturnARecordset does just that...

\'do something with rs

rs.Close
set rs = Nothing

Is i

4条回答
  •  时光说笑
    2021-02-13 19:52

    You can run into ODBC or OLEDB Pooling issues, which keep a connection open and tie up a pool slot:

    Common causes of connection creep include:

    The ADO Connection and Recordset objects are not actually closed. If you don't explicitly close them, they won't be released into the pool. This is probably the single most frequent cause of connection creep.

    An ADO object you created (especially a Connection object) was not explicitly released. Explicitly releasing objects you create is just good programming practice. If you allocate memory, release it. Depending on the language you are using, letting a variable go out of scope may or may not result in it being released.

    See Pooling in the Microsoft Data Access Components

    And if there is any chance of .Net Interop involved be wary: there are lots of warnings about problems caused due to the lazy way COM object (or contained object) release occurs under .Net's garbage collection.

提交回复
热议问题