Results 1 to 5 of 5

Thread: QSqlDatabase::open() fails with QODBC

  1. #1
    Join Date
    May 2006
    Location
    ŁÃ³dź, Poland
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QSqlDatabase::open() fails with QODBC

    [solved]

    Hi everyone,

    I've searched the forum, but none of the previous odbc-related threads has answered my question... I can't open an ODBC data source, my program (sample source below) fails with an obscure error message which reads:

    "Driver not loaded Driver not loaded"

    Yes, it's repeated twice. I try to connect to a database (either MySQL or PostgreSQL) through unix odbc. I have the drivers installed and configured, as well as samle DSNs, and I can browse throug them with DataManager - everything works fine. I've compiled the QSqlODBC plugin from sources (the same version as the library I have installed from Debian's packages) and put it in /usr/lib/qt4/pluings/sqldrivers. The QSqlDatabase::drivers() returns:

    ("QPSQL7", "QPSQL", "QMYSQL3", "QMYSQL", "QSQLITE", "QSQLITE2", "QODBC3", "QODBC")

    Therefore I belive that the plugin is ok. Just to make sure, I've tried to compile it with ODBC_CHECK_DRIVER undefined, as suggested in the documentation - no luck.

    My code looks like:

    Qt Code:
    1. db.addDatabase("QODBC");
    2. db.setDatabaseName("Driver={MySQL};Server=localhost;Database=test;Uid=test;Pwd=test;");
    3. if(!db.open()) {
    4. qDebug() << db.lastError().text();
    5. exit(1);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Any clues?
    Last edited by grzywacz; 22nd August 2006 at 17:51.
    Kind regards,
    Karol "grzywacz" Nowak

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabase::open() fails with QODBC

    I suppose that the OBDC driver depends on some other lib/plug-in at a lower level. Is that dependency in place?

  3. #3
    Join Date
    May 2006
    Location
    ŁÃ³dź, Poland
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlDatabase::open() fails with QODBC

    I'm not aware of any extra dependencies. The unix odbc libraries are installed in /usr/lib, so the dynamic linker shouldn't have any problems finding them. In turn, the unix odbc seems to be properly configured, as the admin tools work ok. I've tried using strace, but nothing meaningful has shown up.
    Kind regards,
    Karol "grzywacz" Nowak

  4. #4
    Join Date
    May 2006
    Location
    ŁÃ³dź, Poland
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlDatabase::open() fails with QODBC

    Ok, I've just solved it - I've made a mistake in another place, sorry for the useless thread.
    Kind regards,
    Karol "grzywacz" Nowak

  5. #5
    Join Date
    Apr 2010
    Location
    United States
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabase::open() fails with QODBC

    Quote Originally Posted by grzywacz View Post
    Yes, it's repeated twice.
    This is because the text() method of QSqlError instance concatenates the driver and database error text most likely.

    Qt Code:
    1. db.addDatabase("QODBC"); // addDatabase returns an initialized instance (loads driver)
    2. db.setDatabaseName("Driver={MySQL};Server=localhost;Database=test;Uid=test;Pwd=test;"); // for the database name you'll want to pass the DSN name when using ODBC
    3. if(!db.open()) {
    4. qDebug() << db.lastError().text();
    5. exit(1);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Try something like this:

    Qt Code:
    1. QSqlDatabase db(QSqlDatabase::addDatabase("QODBC"));
    2. db.setDatabaseName("test"); // be sure to define a DSN with whatever name you pass here
    3. if (!db.open())
    4. qDebug() << db.lastError().text();
    To copy to clipboard, switch view to plain text mode 

    cheers

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.