mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.95k stars 563 forks source link

conn.close() but MS Access .laccdb (lock) file stays open #1279

Closed ScotterMonk closed 1 year ago

ScotterMonk commented 1 year ago

Environment:

My issue:

Open database, read & write <-- all works fine. At end conn.close() .Laccdb file (MS Access lock file) stays visible in folder next to the .accdb file. It's not a "slow" thing. I refresh, wait, etc. and that .Laccdb file is still there. I can delete it manually but would like this to work the way it is supposed to. Until I can figure out an elegant fix, I'll have my program delete the file.

gordthompson commented 1 year ago

Does the .laccdb file remain if you simply open the connection, wait a couple of seconds, and then close the connection?

import time

import pyodbc

connection_string = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=…"
cnxn = pyodbc.connect(connection_string)
sleep_time = 3
print(f"Connected. Pausing for {sleep_time} seconds.")
time.sleep(sleep_time)
print("Closing connection.")
cnxn.close()
v-chojas commented 1 year ago

It may be a driver bug, could you post an ODBC trace? The driver is supposed to cleanup upon connection close but perhaps it isn't doing that.

gordthompson commented 1 year ago

Also, when you say "At end conn.close()" does it mean that your script terminates immediately after the .close()?

ScotterMonk commented 1 year ago

Also, when you say "At end conn.close()" does it mean that your script terminates immediately after the .close()?

Yes and I'm trying your suggestion to put a short sleep after the close.

gordthompson commented 1 year ago

FWIW, I am unable to reproduce your issue with ACE for Access 2013 and an .accdb on my local hard drive. The .laccdb file is removed within one second of calling .close() on the connection, even if the script continues to run. Is your .accdb on a network share, by chance?

ScotterMonk commented 1 year ago

Aha! Dropbox folder. BTW still have not had time to test with new pause-code you recommended.

Sincerely, Scott Swain https://OceanMedia.net

Sent with Proton Mail secure email.

------- Original Message ------- On Monday, September 25th, 2023 at 14:49, Gord Thompson @.***> wrote:

FWIW, I am unable to reproduce your issue with ACE for Access 2013 and an .accdb on my local hard drive. The .laccdb file is removed within one second of calling .close() on the connection, even if the script continues to run. Is your.accdb on a network share, by chance?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>