Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ScotterMonk opened this issue Sep 23, 2023 · 6 comments
Closed

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

ScotterMonk opened this issue Sep 23, 2023 · 6 comments

Comments

@ScotterMonk
Copy link

Environment:

  • Python 3.11
  • pyodbc latest
  • OS: Windows 11
  • DB: MS Access 2019
  • driver: ODBC

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
Copy link
Collaborator

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
Copy link
Contributor

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
Copy link
Collaborator

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

@ScotterMonk
Copy link
Author

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
Copy link
Collaborator

gordthompson commented Sep 25, 2023

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
Copy link
Author

ScotterMonk commented Sep 25, 2023 via email

@gordthompson gordthompson changed the title conn.close() but MS Access Laccdb (lock) file stays open conn.close() but MS Access .laccdb (lock) file stays open Sep 25, 2023
Repository owner locked and limited conversation to collaborators Sep 25, 2023
@gordthompson gordthompson converted this issue into discussion #1280 Sep 25, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

3 participants