[RESOLVED] Record-locking file not being deleted
Hi,
I have a small application that connects to an Access database, makes a change in one row, then disconnects. While it's connected, it creates a record-locking file (.ldb), but this doesn't seem to be removed when the user disconnects from the database. The only way to clear it is to open and close the database in Access.
This is the code (in a module):
VB Code:
Option Explicit
'The connection object for the database, used throughout the application
Public objConn As ADODB.Connection
'A function to create the database connection
'-Requires a path to the database (strPath)
'-Requires a password for the database (strDatabasePassword)
'-Returns true if connection made
'-Returns false if no connection as database does not exist
Function ConnectToDatabase(ByVal strPath As String, _
ByVal strDatabasePassword As String) As Boolean
'Change the pointer to an hourglass
Screen.MousePointer = vbHourglass
'If the database exists
If Dir(strPath) <> "" Then
'Make objConn a new instance of the ADODB.Connection class
Set objConn = New ADODB.Connection
'Define the connection string for the database
'-Microsoft Jet 4.0 is the Provider
'-The database path is passed as an argument to the function
'-Access mode is not limited to prevent errors
'-The user connects as Admin to allow any changes to be made
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPath & ";" & _
"Mode=Share Deny None;" & _
"User ID=Admin;"
'The password for the database is passed as an argument to the function
objConn.Properties("Jet OLEDB:Database Password") = strDatabasePassword
'Open the connection object
objConn.Open
'Connection made
ConnectToDatabase = True
Else
'If the database does not exist, return false
ConnectToDatabase = False
End If
'Set the pointer back to normal
Screen.MousePointer = vbDefault
End Function
'Routine to disconnect from the database
Sub DisconnectFromDatabase()
'Check that the connection is not already closed
If objConn.State <> adStateClosed Then
'Close the connection
objConn.Close
End If
'Set it to nothing
Set objConn = Nothing
End Sub
Any ideas?
Re: Record-locking file not being deleted
This turned out to be an obvious one!
My VB code is fine (as you'd expect ;) ) - it turned out I hadn't clicked the 'Modify' box for the folder permissions, so users could create the file, but not delete it.