PDA

View Full Version : ODBC drvers



mak_user
22nd February 2011, 00:17
Hi,

I would lke to established connection to Microsoft Access database.
I am using:
-QT bin installed(for which I thought include all drivers installed once the bin package is installed)
-Ubuntu operating system
-MS Access database on windows7 system.



QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
qDebug() << QSqlDatabase::drivers();
db.setHostName("0.0.0.0");
db.setDatabaseName("data_source_name");

if (!db.open()) {
QString err = db.lastError().text();
QMessageBox::warning(0, qApp->tr("Cannot open database"),
err, "OK");
return false;
}



I got this errors at QSqlDatabase::addDatabase("QODBC"):
QSqlDatabase: QODBC driver not loaded
QSqlDatabase: available drivers: QSQLITE QPSQL7 QPSQL

and this info at QSqlDatabase::drivers():
("QSQLITE", "QPSQL7", "QPSQL")

So, obviously I can not use QODBC. Could you please help me with some info like, where can I find this drivers and how to install them to be available in QT enviroment?

thanks

schnitzel
22nd February 2011, 01:21
Not all sql drivers are installed by default.
This might be helpful: http://doc.qt.nokia.com/latest/sql-driver.html

ChrisW67
22nd February 2011, 01:33
Are you building code to run on Windows or Linux?

The QODBC driver is available on Windows by default.

You may (don't know, never tried it) be able to build unixODBC and then QODBC on top of that but you will still have to come up with an ODBC driver and/or glue for the Linux platform that can do Access natively. Alternatively, the ODBC Bridge for Linux might be able to get you there in a client-server fashion.
http://www.easysoft.com/developer/libraries/qt/odbc.html
http://www.easysoft.com/products/data_access/odbc_odbc_bridge/index.html

marcvanriet
22nd February 2011, 11:46
If you are running on Windows (don't know about Linux) :

You must use the right description for the driver when you open the database. E.g. this is what I use : ('PcbDatabase' is just some name I made up, is not required)

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "PcbDatabase" );
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MSAccess};DBQ=" + sFileName );


Regards,
Marc

mak_user
22nd February 2011, 15:28
Hi,

I successfully compiled QODBC driver for Linux environment. This is the error I get now trying to connect.



QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
db.setConnectOptions("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3"); // set ODBC options
qDebug() << "DRIVERS :" << QSqlDatabase::drivers();
db.setHostName("0.0.0.0");
db.setDatabaseName("test");

if (!db.open()) {
qDebug() << "LAST ERROR: " << db.lastError().text();
return false;
}


DRIVERS : ("QSQLITE", "QODBC3", "QODBC", "QPSQL7", "QPSQL")
LAST ERROR: "[unixODBC][Driver Manager]Data source name not found, and no default driver specified QODBC3: Unable to connect"

Although I have DSN defined on windows machine. Could you help with some hints?

ChrisW67
23rd February 2011, 04:29
Did I read that right? You have a DSN defined on a Windows machine and are expecting it to be accessed by a program running on a separate Linux machine without any configuration.

You need to use the ODBC-ODBC Bridge (OOB) driver on the Linux side to talk to an agent on the Windows machine using the "test" DSN. The DSN on the Linux (client) side will use the OOB driver and parameters to connect to the server side. You will need to be running the bridge server software on the Windows machine.

http://www.easysoft.com/products/data_access/odbc_odbc_bridge/index.html
and an example configuration in:
http://www.easysoft.com/products/data_access/odbc_odbc_bridge/manual/connection.html#850417

mak_user
23rd February 2011, 11:55
Thanks Chris,

I understand.
Is there any other way that I can read .mdb file from windows machine, not using (OOB)? Can I at least access .mdb if I copy it to linux machine?

schnitzel
23rd February 2011, 16:43
you could try Access to SQL server upscaling (SQL as a backend).

I got so fed up with Access that I decided to migrate it to MySQL and are now using my own Qt front end gui.

ChrisW67
23rd February 2011, 21:49
I am not aware of any Linux native code that can read and write Jet databases directly. Does your data have to stay in an Access format? In my experience most Access databases are little more than a collection of tables that could easily be transferred into Sqlite (for a single-user application), Mysql, or Postgresql (multi-user options). MDBTools (http://mdbtools.sourceforge.net/) can potentially help with data migration although it may be easier to export on the Windows machine using MS Access itself.