0
votes

Following is the configuration: 1.Python - Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32 2.MS Access 2016 MSO(16.0.12624.20348) 64 bit 3.Microsoft Access Driver (*.mdb, *.accdb) 16.00.4513.1000 4.Installed Microsoft Access Database Engine 2016 Redistributable

Facing the error while trying to create a connection:

import pyodbc

conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\tejas\Documents\First.accdb;') cursor = conn.cursor()

Error: Traceback (most recent call last): File "C:\Users\tejas\eclipse-workspace\HelloWorld\DB\Insert.py", line 3, in conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\tejas\Documents\First.accdb;') pyodbc.Error: ('HY000', '[HY000] [Microsoft][ODBC Microsoft Access Driver] The database you are trying to open requires a newer version of Microsoft Access. (-1073) (SQLDriverConnect); [HY000] [Microsoft][ODBC Microsoft Access Driver] The database you are trying to open requires a newer version of Microsoft Access. (-1073)')

I have gone through other similar questions and tried various options but no luck so far. Any help would be appreciated.

2
Try running this code against the file you want to open. What "file type" does it report?Gord Thompson
Hi Gord@Gord Thompson, Output : file type 5Tejas Kore

2 Answers

0
votes

[Microsoft][ODBC Microsoft Access Driver] The database you are trying to open requires a newer version of Microsoft Access.

Running this code:

# path to the file you want to check
file_path = r"C:\Users\Public\my_db.accdb"

with open(file_path, "rb") as f:
    type_byte = f.read(21)[20]
    print(f"file type {type_byte}")

produced "file type 5", confirming that it is an Access 2016 database file which has been modified to include columns of the new "Large Number" (BIGINT) type.

Unfortunately, the Access 2016 Database Engine redistributable has not been updated to work with these files, so at the moment the ACE ODBC driver will throw the above error if we try.

I don't know if the Access 2016 Runtime has been updated to work with these files. I sort of doubt it, but if it has then it might allow us to work with such files using ACE.DAO via pywin32. (Never tried.)

0
votes

I found this because I added a table to a MS Access database and set one of the fields to "Large Number". This broke my connection with pyodbc, and consequently my python scripts which write to this database. I had no way to revert the file.

I fixed it by creating a new database and importing all the old tables that didn't have any Large Number fields. I then was able to simply copy and paste the queries and forms over to the new database file. It seems to work fine now with the new file. I've learned by lesson and won't be assigning "large number" to anything soon in MS Access.

Thanks!