什么时候是“db.close”需要? [英] When is "db.close" needed?
问题描述
A2K app:
问题:是必要的标记行(<<<<<<<<<<<<<<<如果该行需要
,它对于相同的数据库是链接的后端数据库这个事实有什么影响(如果有的话)?
Dim db作为DAO.Database
Dim rst作为DAO.Recordset
设置db = DBEngine.Workspaces(0)。 OpenDatabase(" C:\ AppDir \")
设置rst = db.OpenRecordset(" tblStoredUserChoices",dbOpenTable)
如果是rst !GroupVersion =" G1VER"然后
IsRMTGver =真
否则
IsRMTGver = False
结束如果
rst.Close
Set rst = Nothing
db.Close<<<这行必要吗?
设置db = Nothing
A2K app:
Question: is the flagged line (<<<) below necessary. If that line is
needed, what effect does it have (if any) on the fact that the very
same database is the linked back end db?
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = DBEngine.Workspaces(0).OpenDatabase("C:\AppDir\")
Set rst = db.OpenRecordset("tblStoredUserChoices", dbOpenTable)
If rst!GroupVersion = "G1VER" Then
IsRMTGver = True
Else
IsRMTGver = False
End If
rst.Close
Set rst = Nothing
db.Close <<< is this line necessary?
Set db = Nothing
推荐答案
真的在这一个人身上摸不着头脑。任何建议都会很多
赞赏。
我问这个因为我怀疑以下错误是某种方式
涉及的事实是我的应用启动例程的一部分,我打开
并关闭后端数据库几次从配置表中检索各种
公共变量。为了解决疑似问题,我将变量重新分组为单个
" opendatabase"会话。这对问题没有任何影响。
这个最近刚开始发生在我们5岁的应用程序中
,直到最近一段时间之后一直坚如磐石更新。当
发生以下错误时,逃脱的唯一方法是使用任务管理器终止
流程。
- --------------------------
Form_frmApp_Title.cmdExit_Click
----- ----------------------
错误2501:关闭动作被取消。
--- ------------------------
OK
--------- ------------------
ANYWHERE没有代码取消标题的关闭动作
屏幕表格。
2005年4月7日星期四00:08:12 -0500,Lauren Wilson
< pr ***** @ private .COM>写道:
Really scratching my head on this one folks. Any advice will be much
appreciated.
I ask about this because I SUSPECT that the following error is somehow
involved with the fact that as part of my app startup routine, I open
and close the back-end database several times to retrieve various
public variables from the configuration tables. To cure that
suspected problem, I re-grouped my variables into a single
"opendatabase" session. That had zero effect on the problem.
This only RECENTLY started happening to our 5 year old application
that has been solid as a rock until after some recent updates. When
the error below happens, the ONLY way to escape is to terminate the
process using the Task Manager.
---------------------------
Form_frmApp_Title.cmdExit_Click
---------------------------
Error 2501: The Close action was canceled.
---------------------------
OK
---------------------------
There is NO code ANYWHERE that cancels the close action for the title
screen form.
On Thu, 07 Apr 2005 00:08:12 -0500, Lauren Wilson
<pr*****@private.com> wrote:
A2K app:
问题:是必要的标记行(<<<<<<<<<<<<<<<<<<<如果需要该行,它对于相同的数据库是链接的后端数据库有什么影响(如果有的话)?
Dim db As DAO .Database
Dim rst as DAO.Recordset
设置db = DBEngine.Workspaces(0).OpenDatabase(" C:\ AppDir \")
设置rst = db.OpenRecordset(" tblStoredUserChoices",dbOpenTable)
如果是rst!GroupVersion =" G1VER"然后
IsRMTGver = True
其他
IsRMTGver = False
结束如果
rst.Close
设置rst = Nothing
db .Close<<<这行必要吗?
设置db = Nothing
A2K app:
Question: is the flagged line (<<<) below necessary. If that line is
needed, what effect does it have (if any) on the fact that the very
same database is the linked back end db?
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = DBEngine.Workspaces(0).OpenDatabase("C:\AppDir\")
Set rst = db.OpenRecordset("tblStoredUserChoices", dbOpenTable)
If rst!GroupVersion = "G1VER" Then
IsRMTGver = True
Else
IsRMTGver = False
End If
rst.Close
Set rst = Nothing
db.Close <<< is this line necessary?
Set db = Nothing
2005年4月7日星期四00:08:12 -0500, Lauren Wilson< pr ***** @ private.com>写道:
On Thu, 07 Apr 2005 00:08:12 -0500, Lauren Wilson <pr*****@private.com> wrote:
A2K app:
问题:是必要的标记行(<<<<<<<<<<<<<<<<<<<如果需要该行,它对于相同的数据库是链接的后端数据库有什么影响(如果有的话)?
Dim db As DAO .Database
Dim rst as DAO.Recordset
设置db = DBEngine.Workspaces(0).OpenDatabase(" C:\ AppDir \")
设置rst = db.OpenRecordset(" tblStoredUserChoices",dbOpenTable)
如果是rst!GroupVersion =" G1VER"然后
IsRMTGver = True
其他
IsRMTGver = False
结束如果
rst.Close
设置rst = Nothing
db .Close<<<是否需要此行?
设置db = Nothing
A2K app:
Question: is the flagged line (<<<) below necessary. If that line is
needed, what effect does it have (if any) on the fact that the very
same database is the linked back end db?
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = DBEngine.Workspaces(0).OpenDatabase("C:\AppDir\")
Set rst = db.OpenRecordset("tblStoredUserChoices", dbOpenTable)
If rst!GroupVersion = "G1VER" Then
IsRMTGver = True
Else
IsRMTGver = False
End If
rst.Close
Set rst = Nothing
db.Close <<< is this line necessary?
Set db = Nothing
使用DAO对象时,资源并不总是正确释放,除非DAO
对象关闭,然后以反向依赖顺序释放。可能是
在某些情况下可以安全地省略某些步骤,
但我们都不确定它们是什么,我们也不记得是否我们做到了。这是最安全的,然后,总是做所有的拆卸步骤。
但要小心,不要关闭物体代码中没有明确地打开它们。例如,不要关闭由
调用CurrentDB检索的数据库引用。如果您打开它,请将其关闭。如果你没有打开它,就不要闭上它。
When using DAO objects, resources are not always released properly unless DAO
objects are closed, then released in reverse dependency order. It may be that
there are certain steps of that which could be safely omitted in all cases,
but none of us is sure what they are, nor could we remember if we did. It''s
safest, then, to always do all the tear-down steps.
Be careful, though, and don''t close objects in code that does not explicitly
open them. Do not, for instance, close a database reference retrieved by
calling CurrentDB. If you opened it, close it. If you didn''t open it, don''t
close it.
" Lauren Wilson" < PR ***** @ private.com>在消息中写道
news:pn ******************************** @ 4ax.com ...
"Lauren Wilson" <pr*****@private.com> wrote in message
news:pn********************************@4ax.com...
rst.Close
设置rst = Nothing
db.Close<<<这行必要吗?
设置db = Nothing
rst.Close
Set rst = Nothing
db.Close <<< is this line necessary?
Set db = Nothing
我从v1.00(1992)开始使用Access。
>
很少使用rst.Close:
Set rst = CurrentDb.OpenRecordset(xxxxx)
rst.Close
Set rst = CurrentDb.OpenRecordset(yyyyy)
从未使用过:
Set rst = Nothing
db.Close
设置db = Nothing
我认为它们是一种冗余,很多程序员使用
。因为它是我。
或者我从未遇到过需要它们的情况。
布鲁诺
I''m using Access since v1.00 (1992).
Rarely used rst.Close:
Set rst=CurrentDb.OpenRecordset(xxxxx)
rst.Close
Set rst=CurrentDb.OpenRecordset(yyyyy)
Never used:
Set rst = Nothing
db.Close
Set db = Nothing
I think they are a sort of redundancy many programmers
use. As it is Me.
Or I never met the the circumstance that requires them.
Bruno
这篇关于什么时候是“db.close”需要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!