Qt to open .mdb file, failed at IM002 QODBC: Unable to connect
-
So I want to read the .mdb file with Qt, and I am stuck at IM002 QODBC: Unable to connect. Already posted on question StackOverflow but regarded as Duplicate. Already checked the bitness and driver name as in this question: Why am I getting "Data source name not found and no default driver specified" and how do I fix it? and still failed.
Checking if the file exists, return true. Checking if the driver exists and is valid, return true. Create a dummy file with MS Access 64bit on same Laptop (since mykit is Qt 6.7 64bit to avoid 32bit vs 64bit difference) still creating that error.
Here is my code snippet
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); QString path = "F:\\SKJ Trial\\test data\\Dummy_64bit.mdb"; QString str_comm = "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ="; qDebug() << "Is Db valid: " + QVariant(db.isValid()).toString(); qDebug() << "path: " + path; qDebug() << "Is file exist: " + QVariant(QFile(path).exists()).toString(); str_comm += path; db.setDatabaseName(str_comm); qDebug() << "String command: " + str_comm; db.open(); if(db.isOpen()){ qDebug() << "Success"; } else { qDebug() << "Failed"; qDebug() << db.lastError().text(); }
and the console log is here:
"Is Db valid: true" "path: F:\\SKJ Trial\\test data\\Dummy_64bit.mdb" "Is file exist: true" "String command: DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=F:\\SKJ Trial\\test data\\Dummy_64bit.mdb" Failed "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, IM002 QODBC: Unable to connect"
Could anyone help me if I'm missing something?
-
I can see nothing wrong with the advice in the Stack Overflow post you linked to.
The other thing to be aware of is that you must be checking the 64-bit or 32-bit ODBC manager as appropriate for the bit-ness (word?) of your executable. Your 64-bit tool chain can make a 32-bit application. The drivers are separate and it is very easy to look at the wrong set. See this for example of ODBC confusion:
Other things to try:
- Use a path that does not contain a space
- Define a dedicated data source in ODBC manager and connect using that name
-
Also see https://forum.qt.io/topic/155973
-
@Christian-Ehrlicher Thanks dude, after trying the same code with Qt 6.6.3 the connection works. So we just need to wait for a patch for this problem. Dang, I thought there was an error in my code or my setup.
-
-