问题描述
Dim rs as ADODB.Recordset
set rs = ReturnARecordset 'assume ReturnARecordset does just that...
'do something with rs
rs.Close
set rs = Nothing
调用rs.Close,然后将其设置为无?
Is it necessary to call rs.Close before setting it to nothing?
编辑:我们有一个全局连接,我们在应用程序期间保持打开,所有记录集对象使用此相同的连接。我看到两个答案下面谈到需要关闭记录集,以确保连接不挂开。对我来说,听起来像很多傻的谈话,因为连接是由连接对象控制,而不是记录集对象权利?但请让我知道,如果我在这里缺少的东西...
We have one global connection that we keep open for the duration of the application and all recordset objects use this same connection. I see two answers below talking about the need to close recordsets in order to ensure connections aren't left hanging open. To me that sounds like a lot of silly talk because connections are controlled with connection objects, not recordset objects right? But please let me know if I'm missing something here...
推荐答案
调用关闭
显式是当你不确定记录集是否从项目中的其他地方引用,通常是一些草率编码的结果。
The only reason calling Close
explicitly is when you are not sure if the recordset is referenced from somewhere else in your project, usually a result of some sloppy coding.
Dim rs as ADODB.Recordset
Set rs = ReturnARecordset
...
MyControl.ObscureMethod rs
...
Set rs = Nothing
最后一行应该终止记录集实例而不调用 Close
,除非 MyControl
持有额外的引用,从而防止正常拆除。调用关闭
在
rs
将确保 MyControl
参考任何有用的东西,同时在火焰中坠毁。
Last line is supposed to terminate the recordset instance without calling Close
explicitly, unless MyControl
is holding an extra reference and thus preventing normal tear-down. Calling Close
on rs
will make sure MyControl
cannot use its reference for anything useful, crashing in flames in the meantime.
这篇关于是否有必要在将Adodb.recordset对象设置为无内容之前关闭它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!