为什么即使在只读时,ADO连接仍然会创建“ldb”锁定文件?

时间:2022-09-11 16:57:02

Quick question for you database experts. See the following code (VBA/ADO), called from Excel:

快速提问数据库专家。请参阅从Excel调用的以下代码(VBA / ADO):

Dim DBPath As String, ConnStr As String
DBPath = ThisWorkbook.Path & Application.PathSeparator & "Database.mdb"
ConnStr = "Data Source=" & DBPath & ";" & "Jet OLEDB:Database Password=" & DBPass()
Dim cnn as ADODB.Connection
Set cnn = New ADODB.Connection
With cnn
    .Provider = CheckProvider(strPath:=DBPath) ' Separate function call. Ignore
    .Mode = adModeRead
    .Open ConnStr
End With
Stop ' To inspect the directory...

It should open the database as read-only, given the "adModeRead" specification. However I have noticed that a lock file (Database.ldb) is still being created/deleted in the directory while the connection is active. Surely this goes contrary to the read-only command, which should mean that no data may be written, and therefore no file lock is needed.

在给定“adModeRead”规范的情况下,它应该以只读方式打开数据库。但是我注意到,当连接处于活动状态时,仍在目录中创建/删除锁定文件(Database.ldb)。当然这与只读命令相反,这意味着不能写入任何数据,因此不需要文件锁定。

Can anyone explain what's happening here? Thanks.

谁能解释这里发生了什么?谢谢。

Edit: And a follow-up - if I wanted to open the connection as purely read-only without creating any lock file, is there any other method?

编辑:和后续 - 如果我想打开连接纯粹只读而不创建任何锁定文件,还有其他方法吗?

1 个解决方案

#1


3  

The lock file records connections to the db file. That information is important in a multi-user context. Even if yours is the only connection and is intentionally read-only, Access still records that connection in the lock file. It would be important in a situation where another used wanted to connect to the same db file in exclusive mode in order to make design changes --- they would not be allowed exclusive access while your connection is still active.

锁定文件记录与db文件的连接。该信息在多用户环境中很重要。即使您的连接是唯一的连接并且是有意读取的,Access仍会在锁定文件中记录该连接。在另一个使用过的人希望以独占模式连接到同一个db文件以进行设计更改的情况下,这将非常重要 - 在您的连接仍处于活动状态时,不允许独占访问。

#1


3  

The lock file records connections to the db file. That information is important in a multi-user context. Even if yours is the only connection and is intentionally read-only, Access still records that connection in the lock file. It would be important in a situation where another used wanted to connect to the same db file in exclusive mode in order to make design changes --- they would not be allowed exclusive access while your connection is still active.

锁定文件记录与db文件的连接。该信息在多用户环境中很重要。即使您的连接是唯一的连接并且是有意读取的,Access仍会在锁定文件中记录该连接。在另一个使用过的人希望以独占模式连接到同一个db文件以进行设计更改的情况下,这将非常重要 - 在您的连接仍处于活动状态时,不允许独占访问。