Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is an ADO connection still creating an "ldb" lock file even when read-only?

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

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.

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?

like image 320
Chris Melville Avatar asked Oct 19 '22 20:10

Chris Melville


1 Answers

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.

like image 175
HansUp Avatar answered Nov 15 '22 05:11

HansUp