connecting MS Access in Qt 5.15
-
@dan1973
Reinstalling Office is not the issue. I said you need to verify what ODBC connection string is needed/works external to your Qt program.No I don't face such a problem as I don't use Windows for programming. When I have in the past you have to get the ODBC connection string correct.
-
@JonB
Following is the output i get in excel when i run the prepared dqy file(see dqy file also below)
Excel output:
dqy file:
XLODBC 1 Driver={Microsoft Access Driver (*.mdb)};DSN='ms32';DBQ=C:\\LCA_MC.mdb; SELECT BusName FROM BusInfo
I then used the Driver string in my code still the same problem.
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb)};DSN='ms32';DBQ=C:\\LCA_MC.mdb;"); if(db.open()) qDebug() << "oK"; else qDebug() << db.lastError().text();
-
@dan1973
There are loads of Google hits for"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
.I think you are supposed to go into ODBC Data Source Administrator (32-bit? 64-bit? I think it's important you configure whatever the right one is being used by your Qt program) and have a look through the tabs to see what is configured/available to you.
So far as I can see the Qt ODBC driver is installed correctly and the error comes from the ODBC driver on the connection string.
-
@dan1973 Further to what @JonB noted, the examples on the Connection Strings site for an ODBC connection to Access are of the form:
Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\mydatabase.accdb;...
I expect if you open the ODBC admin tool this is exactly the name you will see on the system drivers tab.
Notice that the driver name here includes two different file extensions and differs from yours:
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.accdb;...
-
I used the following codes:
1.QString strDatabasePath = "C:/LCA_MC.mdb"; QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); QString strDbName = QString("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=%1").arg(strDatabasePath); //db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=c:/ada.mdb"); db.setDatabaseName(strDbName); bool ok = db.open(); if(ok) qDebug() << "Success"; else qDebug() << db.lastError().text();
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); QString strDbName = QString("Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\\LCA_MC.mdb;Uid=;Pwd=;"); db.setDatabaseName(strDbName); bool ok = db.open(); if(ok) qDebug() << "Success"; else qDebug() << db.lastError().text();
Still i get the same error:
"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"I have a doubt: why QODBC3? since i am using QODBC.
-
Also, be aware that the Access ODBC connector is likely 32-bit so your application has to be 32-bit. It's been quite a while since I used the Access ODBC with Qt, but I remember trying to install a 64-bit version of the connector but that created other MS Office issues.
-
@mchinand
I tried pointing this out to the OP earlier withI think you are supposed to go into ODBC Data Source Administrator (32-bit? 64-bit? I think it's important you configure whatever the right one is being used by your Qt program) and have a look through the tabs to see what is configured/available to you.
but don't hear much back that s/he has tried.