简体   繁体   中英

Connect to MS access database using PyQt5

I'm trying to connect to a MS access database using the following code:

from PyQt5.QtSql import QSqlDatabase

db = QSqlDatabase.addDatabase("QODBC")
db.setDatabaseName(
        "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\\database.accdb")
if db.open(): print("opened")

I have office 2019 installed. I cannot figure out what is wrong in the connection string or the driver.

I figured out that this problem happened because I have a 64-bit of python and a 32-bit of access database engine driver.

After installing the 64-bit access database engine driver, I managed to get it work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM