Results 1 to 9 of 9

Thread: ODBC drvers

  1. #1
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    11
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default ODBC drvers

    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.

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    2. qDebug() << QSqlDatabase::drivers();
    3. db.setHostName("0.0.0.0");
    4. db.setDatabaseName("data_source_name");
    5.  
    6. if (!db.open()) {
    7. QString err = db.lastError().text();
    8. QMessageBox::warning(0, qApp->tr("Cannot open database"),
    9. err, "OK");
    10. return false;
    11. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ODBC drvers

    Not all sql drivers are installed by default.
    This might be helpful: http://doc.qt.nokia.com/latest/sql-driver.html

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: ODBC drvers

    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/li...s/qt/odbc.html
    http://www.easysoft.com/products/dat...dge/index.html

  4. #4
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ODBC drvers

    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)
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "PcbDatabase" );
    2. db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MSAccess};DBQ=" + sFileName );
    To copy to clipboard, switch view to plain text mode 

    Regards,
    Marc

  5. #5
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    11
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ODBC drvers

    Hi,

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

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
    2. db.setConnectOptions("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3"); // set ODBC options
    3. qDebug() << "DRIVERS :" << QSqlDatabase::drivers();
    4. db.setHostName("0.0.0.0");
    5. db.setDatabaseName("test");
    6.  
    7. if (!db.open()) {
    8. qDebug() << "LAST ERROR: " << db.lastError().text();
    9. return false;
    10. }
    To copy to clipboard, switch view to plain text mode 

    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?

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: ODBC drvers

    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/dat...dge/index.html
    and an example configuration in:
    http://www.easysoft.com/products/dat...on.html#850417
    Last edited by ChrisW67; 23rd February 2011 at 05:58.

  7. The following user says thank you to ChrisW67 for this useful post:

    mak_user (23rd February 2011)

  8. #7
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    11
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ODBC drvers

    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?

  9. #8
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ODBC drvers

    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.

  10. The following user says thank you to schnitzel for this useful post:

    mak_user (23rd February 2011)

  11. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: ODBC drvers

    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 can potentially help with data migration although it may be easier to export on the Windows machine using MS Access itself.

  12. The following user says thank you to ChrisW67 for this useful post:

    mak_user (23rd February 2011)

Similar Threads

  1. Frustrated with ODBC
    By darkadept in forum Qt Programming
    Replies: 3
    Last Post: 8th December 2011, 03:31
  2. SQL Anywhere ODBC
    By derick in forum Qt Programming
    Replies: 6
    Last Post: 22nd December 2009, 04:04
  3. QT library & ODBC
    By smrtak in forum Qt Programming
    Replies: 3
    Last Post: 27th September 2009, 21:14
  4. ODBC to mssql2008express
    By LordQt in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2009, 15:09
  5. KDevelop + ODBC + Qt
    By cleber in forum Qt Programming
    Replies: 7
    Last Post: 6th June 2008, 21:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.