Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QODBC
Qt 6.11 is out! See what's new in the release blog

QODBC

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 6 Posters 10.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • linaL lina

    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?

    beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by beecksche
    #3

    @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.

    1 Reply Last reply
    1
    • michalosM Offline
      michalosM Offline
      michalos
      wrote on last edited by
      #4

      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?

      linaL 1 Reply Last reply
      0
      • michalosM michalos

        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?

        linaL Offline
        linaL Offline
        lina
        wrote on last edited by
        #5

        @michalos
        Hi Michalos
        this is my code:

        QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
        db.setDatabaseName(":memory:");
        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")
        .arg(QDir::toNativeSeparators("../sqlModel/qdn.db"));
        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 :
        0_1484630761423_driverPic.jpg

        also this is sqldrivers in QT installation folder:
        0_1484630971648_Untitled.jpg

        D 1 Reply Last reply
        0
        • linaL lina

          @michalos
          Hi Michalos
          this is my code:

          QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
          db.setDatabaseName(":memory:");
          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")
          .arg(QDir::toNativeSeparators("../sqlModel/qdn.db"));
          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 :
          0_1484630761423_driverPic.jpg

          also this is sqldrivers in QT installation folder:
          0_1484630971648_Untitled.jpg

          D Offline
          D Offline
          Devopia53
          wrote on last edited by
          #6

          @lina

          Hi.

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

          linaL 2 Replies Last reply
          0
          • D Devopia53

            @lina

            Hi.

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

            linaL Offline
            linaL Offline
            lina
            wrote on last edited by lina
            #7

            @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?

            D 1 Reply Last reply
            0
            • linaL lina

              @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?

              D Offline
              D Offline
              Devopia53
              wrote on last edited by Devopia53
              #8

              @lina

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

              1 Reply Last reply
              1
              • michalosM Offline
                michalosM Offline
                michalos
                wrote on last edited by
                #9

                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.

                1 Reply Last reply
                1
                • D Devopia53

                  @lina

                  Hi.

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

                  linaL Offline
                  linaL Offline
                  lina
                  wrote on last edited by lina
                  #10

                  @Devopia53

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

                  1 Reply Last reply
                  0
                  • michalosM Offline
                    michalosM Offline
                    michalos
                    wrote on last edited by
                    #11

                    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

                    linaL 1 Reply Last reply
                    1
                    • michalosM michalos

                      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

                      linaL Offline
                      linaL Offline
                      lina
                      wrote on last edited by
                      #12

                      @michalos

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

                      D 1 Reply Last reply
                      0
                      • linaL lina

                        @michalos

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

                        D Offline
                        D Offline
                        Devopia53
                        wrote on last edited by
                        #13

                        @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 .

                        linaL 1 Reply Last reply
                        1
                        • D Devopia53

                          @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 .

                          linaL Offline
                          linaL Offline
                          lina
                          wrote on last edited by
                          #14

                          @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.

                          1 Reply Last reply
                          1
                          • michalosM Offline
                            michalosM Offline
                            michalos
                            wrote on last edited by
                            #15

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

                            1 Reply Last reply
                            3
                            • I Offline
                              I Offline
                              isan
                              wrote on last edited by isan
                              #16

                              @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

                              @Devopia53
                              It isn't missing from version 5.6.0

                              linaL 1 Reply Last reply
                              1
                              • I isan

                                @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

                                @Devopia53
                                It isn't missing from version 5.6.0

                                linaL Offline
                                linaL Offline
                                lina
                                wrote on last edited by
                                #17

                                @isan

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

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved