Reputation: 1623
I have a code that reads .MDB Database and Converts it to csv file and as my database is in shared network folder, when the code is reading the database others test rigs are unable to write to the database.
i need a way of reading this .mdb as readonly, so that everyone can open it for edit while this code is reading
import pyodbc
DRV = '{Microsoft Access Driver (*.mdb)}'
PWD = ''
mdb = 'C:\newfolder\database.mdb'
con = pyodbc.connect('DRIVER={};DBQ={};PWD={}'.format(DRV, mdb, PWD)) # connect to db
cur = con.cursor()
sql = 'SELECT * FROM CK_Test_Results;' # run a query and get the results
rows = cur.execute(sql).fetchall()
cur.close()
con.close()
with open('Database.csv', 'w', newline='') as fou:
csv_writer = csv.writer(fou) # default field-delimiter is ","
csv_writer.writerows(rows)
Upvotes: 0
Views: 1363
Reputation: 123829
You can force the connection to read-only by appending ;ReadOnly=1
to your connection string. However, it certainly is possible for other users to update the database while you are reading it.
Check the permissions on the folder in which the .mdb file resides; all users of the database must have read/write access to the folder in order for concurrent multi-user access to work properly. See this answer for details.
Upvotes: 1
Reputation: 23012
Edit your ODBC connection file from Control Panel/Administrative Tools. Select the ODBC driver and then click on Configure and then on Options. At the bottom of the displayed window, you should see Exclusive and/or Read Only.
Upvotes: 0