I have a Windows Forms application using a Jet 4.0 local database via OleDb. When the application exits, it attempts to compact & repair the database before performing automatic backups. I'm explicitly closing the OleDb connection before attempting the compact and repair, and sometimes it works exactly as intended. But in some cases (apparently after new columns and tables have been added to the database by the application itself) the compact & repair fails with the error message "You attempted to open a database that is already opened exclusively by user 'Admin' on machine 'ALANM720T'" (curiously, my user name is Alan, not Admin). There are no other connections or processes accessing the database in any way.

After stepping through the code, it appears that the closing of the connection is failing silently in those cases, and the database's .ldb file (which normally goes away as soon as the last connection is closed) persists. For example, the following code produces an infinite loop when executed immediately after the close:
Code:
Do While File.Exists([ldb_filespec])
Loop
Is there something I'm missing here, or some other step I need to take to ensure that the close will be effective in all cases?

Code:
            'JRO is a Jet replication object
            CloseConnection()
            JRO.CompactDatabase([existing_database_filespec], [new_filespec_for_compacted_db]) 'operation fails here after new columns/tables have been added to the database

    Public Sub CloseConnection()
        Try
            If cn IsNot Nothing Then
                If cn.State <> ConnectionState.Closed Then
                    cn.Close()
                End If
                cn.Dispose()
            End If
            cn = Nothing
        Catch ex As Exception
            DisplayException(ex)
        End Try
    End Sub