Reputation: 67
I'm trying to open MS Access db file with QT in Linux. So, I have installed odbc plugin for qt:
sudo apt-get install libqt4-sql-odbc
Now there are 2 files qt4/plugins/sqldrivers
directory: libqodbc.so & libqsqlite.so
So, I try to use ODBC plugin in my project. There is connection function:
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=/home/user/personal_base.mdb");
if (!db.open()) {
QMessageBox::warning(0, QObject::tr("Database Error"), db.lastError().text());
return false;
}
return true;
}
But application dislpays error:
[unixODBC][Driver Manager]Data source name not found, and no default driver specified QODBC3: Unale to connect
How should I fix it?
Upvotes: 2
Views: 2405
Reputation: 1
I had The same Problem with my project except that I'm using Windows. I think that this will help you: Just change Your Driver into this Code(taken from QT Website):
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb");
Upvotes: 0
Reputation: 5992
The call to setDatabaseName ends up in the ODBC function SQLDriverConnect. SQLDriverConnect defines a number of attributes you can set to declare which ODBC driver you are using and how to use it e.g., DRIVER. You told the unixODBC driver manager to load the driver "Microsoft Access Driver (*.mdb, *.accdb)" and it could not find that driver.
In unixODBC, drivers are usually defined in the odbcinst.ini file which you can usually find with the command "odbcinst -j". You'll find this article useful.
It is highly unlikely you have a Microsoft Access driver named as you've shown as this is usually the name of the MS Access driver which is only available on Windows.
To my knowledge there are only 2 ways to access MS Access DB directly from Linux using ODBC 1) mdbtools (which is old and incomplete but free) 2) Easysoft MS Access ODBC Driver which is a complete ODBC Driver but not free.
Upvotes: 1