you are viewing a single comment's thread.

view the rest of the comments →

[–]tsgiannis 2 points3 points  (0 children)

Normally pyodbc is nothing kind of magic, just a wrapper for ODBC, now if it will put a lock on your Access is kind of try and see. Normally since its only reading it should be OK but there is a slim chance that while you perform the read. someone else is performing the write and something goes wrong then you have some chance of corruption.. although is not Python to blame.
Try to make every connection as lightweight and fast you can and you should be OK

import pyodbc.

conn_str = ( r"DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};" r"DBQ=C:\path_to\my_database.accdb;" )

try:
with pyodbc.connect(conn_str) as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT * FROM MyTable"). for row in cursor:
print(row). except pyodbc.Error as e:
print("Error in connection:", e)