unable to open MS-Access DB on QT Application
-
wrote on 26 Oct 2018, 16:42 last edited by
i have a simple program in qt and what is this program do is to open\read a microsoft access datebase (.mdb or .accdb) and display the db tables.
however my problem is that i cant even open the db at the first place
i have db located in the c drive (C:\Qt_Project\Database1.accdb)
in the (.pro) file i have includedQT += core gui sql
included libraries are:
#include <QSqlDatabase> #include <QDebug> #include <QSqlError>
my code is:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC","AccessDB"); db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=C://Qt_Project//Database1.accdb"); if(db.open()) qDebug() << "oK"; else qDebug() << db.lastError().text();
and finally my output is
"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"
i've goggled the web about this problem i'm facing and maybe "not sure" it's because of the registry because i usually use a cleaner to clean my pc which is cleaning registry also
when i use the code
bool ok = QSqlDatabase::isDriverAvailable("QODBC");
it retures
true
that means there is no problems with the driver
please help , thanks u
-
wrote on 26 Oct 2018, 17:31 last edited by
Hi, double forward slashes I think confuses Windows, try backward slashes instead:
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=C:\\Qt_Project\\Database1.accdb");
-
wrote on 26 Oct 2018, 18:25 last edited by mustafa
hello @hskoglund i did what you say and this was the output
QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed. "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"
-
wrote on 26 Oct 2018, 22:48 last edited by
Hmm, try simplifying by skipping the FILxx stuff::
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=C:\\Qt_Project\\Database1.accdb");
Also, check that you have MS-Access installed on your computer and that you can open C:\Qt_Project\Database1.accdb from MS-Access.
-
i have a simple program in qt and what is this program do is to open\read a microsoft access datebase (.mdb or .accdb) and display the db tables.
however my problem is that i cant even open the db at the first place
i have db located in the c drive (C:\Qt_Project\Database1.accdb)
in the (.pro) file i have includedQT += core gui sql
included libraries are:
#include <QSqlDatabase> #include <QDebug> #include <QSqlError>
my code is:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC","AccessDB"); db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=C://Qt_Project//Database1.accdb"); if(db.open()) qDebug() << "oK"; else qDebug() << db.lastError().text();
and finally my output is
"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"
i've goggled the web about this problem i'm facing and maybe "not sure" it's because of the registry because i usually use a cleaner to clean my pc which is cleaning registry also
when i use the code
bool ok = QSqlDatabase::isDriverAvailable("QODBC");
it retures
true
that means there is no problems with the driver
please help , thanks u
-
@mustafa
Please check this:bool ok=QSqlDatabase::isDriverAvailable("QODBC"); if(!ok) { ErrorMsg="No ODBC driver available!"; return 1; }
-
hello @hskoglund i did what you say and this was the output
QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed. "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"
wrote on 27 Oct 2018, 08:46 last edited by@Mustafa
Apart from trying without theFIL=
as @hskoglund has said, is it possible these days you have a 64- vs 32-bit issue with your drivers & Qt & your app? The sort of thing discussed in https://stackoverflow.com/a/25428598/489865 ?Alternatively, have you read the same question from a year ago and resolution at https://forum.qt.io/topic/81321/qtsql-data-source-name-not-found/4 ?
Just a couple of thoughts, no point asking me further about this!
-
This post is deleted!