• Hi

    I have problem with creating QODBC data base. I installed qt 5.6 (32bit) on windows. I always face this "QSqlDatabase: QODBC driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7"

    I checked "C:\Qt\Qt5.6.0\5.6\mingw49_32\plugins\sqldrivers" and noticed that no QODBC dll files exists in this folder. I'm wondering which tool should be installed to solve this problem.

    I downloaded Qt Open Source 5.6. May this version haven't accurate proficiency requirements for using ODCB?

  • Install Qt sources (if you haven't done it yet), navigate to Src\qtbase\src\plugins\sqldrivers\odbc directory and build ODBC plugin:

    mingw32-make install

  • @lina
    Have a look here http://doc.qt.io/qt-5.6/sql-driver.html#qodbc-for-open-database-connectivity-odbc

    As far as i know, in newer versions of Qt ( > 5.6.0) the ODBC driver is installed by default (https://bugreports.qt.io/browse/QTBUG-49420). So you can also download the newest version of Qt, if you do not want to build it by yourself.

  • Hi,
    If You have Qt 5.6 You should have the ODBC driver.
    I think that You should select the ODBC driver, when connecting to the DB.

    Can You paste some code, to show how Your connection to the DB looks like?

  • @michalos
    Hi Michalos
    this is my code:

    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    qDebug() << "db open" << db.open();

    // create a table in the memory DB
    QSqlQuery q_create = db.exec("CREATE TABLE qdn (id int, name varchar(50))");
    qDebug() << "create: " << q_create.lastError();
    // populate with some data
    QSqlQuery q_insert(db);
    q_insert.prepare("INSERT INTO qdn (id, name) VALUES (:id, :name)");
    q_insert.bindValue(":id", QVariant::fromValue(1));
    q_insert.bindValue(":name", "Volker");
    qDebug() << "insert volker: " << q_insert.exec();
    q_insert.bindValue(":id", QVariant::fromValue(2));
    q_insert.bindValue(":name", "Root");
    qDebug() << "insert root: " << q_insert.exec();
    // create a new file based database and attach it
    // to the existing Qt DB handle
    QString sqlAttach = QString("ATTACH DATABASE '%1' AS fileDB")
    QSqlQuery q_attach = db.exec(sqlAttach);
    qDebug() << "attach: " << q_attach.lastError();
    // create the table in the file based DB as a copy
    // of the in memory DB
    QSqlQuery q_create_fdb = db.exec("CREATE TABLE fileDB.qdn AS SELECT * from qdn");
    qDebug() << "create select: " << q_create_fdb.lastError();

    also this is ODBC driver pic on my computer :

    also this is sqldrivers in QT installation folder:

  • @lina


    You can follow the suggestions of @mtrch and @beecksche .
    Please upgrade to version 5.6.1 or higher or build the source.

  • @Devopia53

    Hi Devopia53

    I coulden't find the path : Src\qtbase\src\plugins\sqldrivers\odbc on my computer. however I have the odcb driver in odcb data source administrator window. should I install qt source seprately? where can I download qt source for windows?

  • @lina

    The file you need is plugin(aka qsqlodbc.dll), not ODBC driver.
    You can download separately. Here

  • I'm no expert on ODBC, but I had to connect to a Netezza DB last week and all it took was to:

    1. install the Netezza ODBC driver
    2. configure the ODBC connection in windows (%windir%\system32\odbcad32.exe) and add the DNS user
    3. followed the instruction on http://doc.qt.io/qt-5.7/sql-driver.html
      a) Be aware that when connecting to an ODBC datasource you must pass in the name of the ODBC datasource to the QSqlDatabase::setDatabaseName() function rather than the actual database name.
      b)With Microsoft SQL Server the result set returned by a stored procedure that uses the return statement, or returns multiple result sets, will be accessible only if you set the query's forward only mode to forward using QSqlQuery::setForwardOnly().

    Unfortunetly I don't have the code right now.
    I will try to post it in the next 12h.

  • @Devopia53

    I downloaded Qt Open Source 5.6. May this version haven't accurate proficiency requirements for using ODCB?

  • I have Qt 5.6.2 Open Source and I have the ODBC driver in ‪C:\Qt\5.6\mingw49_32\plugins\sqldrivers\qsqlodbc.dll

  • @michalos

    I don't have this .dll where can I download that? I would be grateful if you could send it for me.

  • @lina

    Due to a simple mistake on the Qt side, it is missing from that version 5.6.0 and is not related to performance.

    It is a simple matter to solve by following the method proposed by @mtrch .

  • @Devopia53 said in QODBC:

    on 5.6.0

    thank you very much. I use the 5.6.0 version. I hit similar solutions everywhere and never find this path on my computer. I'll install a new version.

  • @lina
    Or just use the qt maintenance tool and chose 'update' to 5.6.2

  • @lina
    You just need reinstall qt 5.6.0 and in select components step ,choose select all ,or choose Sources in subset of Qt5.6
    after installation you have src folder in C:\Qt\Qt5.6.0\5.6 and you can find odbc folder in there

    It isn't missing from version 5.6.0

  • @isan

    yeah. I didn't install qt5.6.0 completely. I re-install it and it works now

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.