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 Driver not loaded
Forum Updated to NodeBB v4.3 + New Features

QODBC Driver not loaded

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 6 Posters 913 Views
  • 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.
  • it.aint.meI Offline
    it.aint.meI Offline
    it.aint.me
    wrote on last edited by
    #1

    Hi.
    I'm using QT 5.15.2 on Win 11 x 64 and trying to connect to the MS SQL Server database. There is a problem with the QODBC driver. When I try to execute db->open() I get the message "Driver not loaded Driver not loaded".

    Here's the code:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QSqlDatabase>
    #include <QSqlError>
    #include <QObject>
    #include <QMessageBox>
    #include <iostream>
    #include <QStringList>
    #include <QDebug>
    #include <QtSql>
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        auto *passEdit = ui->lineEdit;
        auto *label = ui->label;
        auto *connectButton = ui->pushButton;
        QString db_password;
        QString mes_text = "";
    
        if (!QSqlDatabase::drivers().contains("QODBC"))
            mes_text = "not ";
        QMessageBox::warning(this, "QODBC test", "QODBC driver " + mes_text + "founded");
    
        //for (auto &Str : QSqlDatabase::drivers())
        //    std::cout << Str.toStdString() << std::endl;
    
    
        QSqlDatabase *db = new QSqlDatabase;
        db->addDatabase("QODBC");
        QString connectionString = "Driver={SQL Server};";
        connectionString.append("Server=RS-FS-03,1433;");
        connectionString.append("Database=TEST_DB;");
        connectionString.append("Uid=USER;");
        connectionString.append("Pwd=PASSWORD");
        db->setDatabaseName(connectionString);
    
        QObject::connect(passEdit, &QLineEdit::textEdited, [&db_password, passEdit](){db_password = passEdit->text();});
    
        QObject::connect(connectButton, &QPushButton::clicked, [db, label](){
            if (db->open()) {
                label->setText("Connected");
            }
            else {
                label->setText("Not connected");
                qDebug() << db->lastError().text();
            }
        });
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    Previously, to install the driver, I ran:
    \Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers>qmake
    \Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers>mingw32-make
    \Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers>mingw32-make install

    and the driver, it seems to me, has been installed.
    I checked in the folder \Qt\5.15.2\mingw81_64\plugins\sqldrivers
    qsqlodbc.dll appeared.
    The list of supported QODBC drivers includes:
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
    Please help me solve the problem.

    C Ketan__Patel__0011K 2 Replies Last reply
    0
    • JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      Set environment variable QT_DEBUG_PLUGINS=1, re-run your app, voluminous diagnostic output, look near the end to see reason why.

      it.aint.meI 1 Reply Last reply
      0
      • JonBJ JonB

        Set environment variable QT_DEBUG_PLUGINS=1, re-run your app, voluminous diagnostic output, look near the end to see reason why.

        it.aint.meI Offline
        it.aint.meI Offline
        it.aint.me
        wrote on last edited by it.aint.me
        #3

        @JonB
        Thank you, JonB. I added in main.cpp such string, as you proposed:
        qputenv("QT_DEBUG_PLUGINS", QByteArray("1"));
        After myapp restart I've got the next output:

        QFactoryLoader::QFactoryLoader() checking directory path ".../Documents/QTProjects/FactoryWorkResults/Slaughter_Results_5-12/build/Desktop_Qt_5_15_2_MinGW_64_bit-Debug/debug/sqldrivers" ...
        QFactoryLoader::QFactoryLoader() looking at ".../Documents/QTProjects/FactoryWorkResults/Slaughter_Results_5-12/build/Desktop_Qt_5_15_2_MinGW_64_bit-Debug/debug/sqldrivers/qsqlodbc.dll"
        Found metadata in lib .../Documents/QTProjects/FactoryWorkResults/Slaughter_Results_5-12/build/Desktop_Qt_5_15_2_MinGW_64_bit-Debug/debug/sqldrivers/qsqlodbc.dll, metadata=
        {
            "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
            "MetaData": {
                "Keys": [
                    "QODBC3",
                    "QODBC"
                ]
            },
            "archreq": 0,
            "className": "QODBCDriverPlugin",
            "debug": false,
            "version": 331520
        }
        
        Got keys from plugin meta data ("QODBC3", "QODBC")
        loaded library "D:/Qt/5.15.2/mingw81_64/plugins/sqldrivers/qsqlodbc.dll"
        QFactoryLoader::QFactoryLoader() checking directory path "D:/Qt/5.15.2/mingw81_64/plugins/accessible" ...
        QFactoryLoader::QFactoryLoader() checking directory path ".../Documents/QTProjects/FactoryWorkResults/Slaughter_Results_5-12/build/Desktop_Qt_5_15_2_MinGW_64_bit-Debug/debug/accessible" ...
        QFactoryLoader::QFactoryLoader() checking directory path "D:/Qt/5.15.2/mingw81_64/plugins/accessiblebridge" ...
        QFactoryLoader::QFactoryLoader() checking directory path ".../Documents/QTProjects/FactoryWorkResults/Slaughter_Results_5-12/build/Desktop_Qt_5_15_2_MinGW_64_bit-Debug/debug/accessiblebridge" ...
        

        After that I click the connectButton and get output:

        "Driver not loaded Driver not loaded"
        

        Thus I got more information, but still don't understand why "driver not loaded".

        Christian EhrlicherC 1 Reply Last reply
        0
        • it.aint.meI it.aint.me

          Hi.
          I'm using QT 5.15.2 on Win 11 x 64 and trying to connect to the MS SQL Server database. There is a problem with the QODBC driver. When I try to execute db->open() I get the message "Driver not loaded Driver not loaded".

          Here's the code:

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          #include <QSqlDatabase>
          #include <QSqlError>
          #include <QObject>
          #include <QMessageBox>
          #include <iostream>
          #include <QStringList>
          #include <QDebug>
          #include <QtSql>
          
          MainWindow::MainWindow(QWidget *parent)
              : QMainWindow(parent)
              , ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
              auto *passEdit = ui->lineEdit;
              auto *label = ui->label;
              auto *connectButton = ui->pushButton;
              QString db_password;
              QString mes_text = "";
          
              if (!QSqlDatabase::drivers().contains("QODBC"))
                  mes_text = "not ";
              QMessageBox::warning(this, "QODBC test", "QODBC driver " + mes_text + "founded");
          
              //for (auto &Str : QSqlDatabase::drivers())
              //    std::cout << Str.toStdString() << std::endl;
          
          
              QSqlDatabase *db = new QSqlDatabase;
              db->addDatabase("QODBC");
              QString connectionString = "Driver={SQL Server};";
              connectionString.append("Server=RS-FS-03,1433;");
              connectionString.append("Database=TEST_DB;");
              connectionString.append("Uid=USER;");
              connectionString.append("Pwd=PASSWORD");
              db->setDatabaseName(connectionString);
          
              QObject::connect(passEdit, &QLineEdit::textEdited, [&db_password, passEdit](){db_password = passEdit->text();});
          
              QObject::connect(connectButton, &QPushButton::clicked, [db, label](){
                  if (db->open()) {
                      label->setText("Connected");
                  }
                  else {
                      label->setText("Not connected");
                      qDebug() << db->lastError().text();
                  }
              });
          }
          
          MainWindow::~MainWindow()
          {
              delete ui;
          }
          

          Previously, to install the driver, I ran:
          \Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers>qmake
          \Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers>mingw32-make
          \Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers>mingw32-make install

          and the driver, it seems to me, has been installed.
          I checked in the folder \Qt\5.15.2\mingw81_64\plugins\sqldrivers
          qsqlodbc.dll appeared.
          The list of supported QODBC drivers includes:
          QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
          Please help me solve the problem.

          C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          @it-aint-me Please compare what you have done:

          QSqlDatabase *db = new QSqlDatabase;
          db->addDatabase("QODBC");
          QString connectionString = "Driver={SQL Server};";
          connectionString.append("Server=RS-FS-03,1433;");
          connectionString.append("Database=TEST_DB;");
          connectionString.append("Uid=USER;");
          connectionString.append("Pwd=PASSWORD");
          db->setDatabaseName(connectionString);
          

          with the example in the QSqlDatabase documentation.

          QSqlDatabase::addDatabase() is a static factory method. You need to capture the return value: that is your connection. There is no need for heap allocation and you are warned about keeping the QSqlDatabase longer than necessary to achieve the immediate task.

          1 Reply Last reply
          1
          • it.aint.meI it.aint.me

            @JonB
            Thank you, JonB. I added in main.cpp such string, as you proposed:
            qputenv("QT_DEBUG_PLUGINS", QByteArray("1"));
            After myapp restart I've got the next output:

            QFactoryLoader::QFactoryLoader() checking directory path ".../Documents/QTProjects/FactoryWorkResults/Slaughter_Results_5-12/build/Desktop_Qt_5_15_2_MinGW_64_bit-Debug/debug/sqldrivers" ...
            QFactoryLoader::QFactoryLoader() looking at ".../Documents/QTProjects/FactoryWorkResults/Slaughter_Results_5-12/build/Desktop_Qt_5_15_2_MinGW_64_bit-Debug/debug/sqldrivers/qsqlodbc.dll"
            Found metadata in lib .../Documents/QTProjects/FactoryWorkResults/Slaughter_Results_5-12/build/Desktop_Qt_5_15_2_MinGW_64_bit-Debug/debug/sqldrivers/qsqlodbc.dll, metadata=
            {
                "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
                "MetaData": {
                    "Keys": [
                        "QODBC3",
                        "QODBC"
                    ]
                },
                "archreq": 0,
                "className": "QODBCDriverPlugin",
                "debug": false,
                "version": 331520
            }
            
            Got keys from plugin meta data ("QODBC3", "QODBC")
            loaded library "D:/Qt/5.15.2/mingw81_64/plugins/sqldrivers/qsqlodbc.dll"
            QFactoryLoader::QFactoryLoader() checking directory path "D:/Qt/5.15.2/mingw81_64/plugins/accessible" ...
            QFactoryLoader::QFactoryLoader() checking directory path ".../Documents/QTProjects/FactoryWorkResults/Slaughter_Results_5-12/build/Desktop_Qt_5_15_2_MinGW_64_bit-Debug/debug/accessible" ...
            QFactoryLoader::QFactoryLoader() checking directory path "D:/Qt/5.15.2/mingw81_64/plugins/accessiblebridge" ...
            QFactoryLoader::QFactoryLoader() checking directory path ".../Documents/QTProjects/FactoryWorkResults/Slaughter_Results_5-12/build/Desktop_Qt_5_15_2_MinGW_64_bit-Debug/debug/accessiblebridge" ...
            

            After that I click the connectButton and get output:

            "Driver not loaded Driver not loaded"
            

            Thus I got more information, but still don't understand why "driver not loaded".

            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @it-aint-me said in QODBC Driver not loaded:

            Projects/FactoryWorkResults/Slaughter_Results_5-12/build/Desktop_Qt_5_15_2_MinGW_64_bit-Debug/debug/sqldrivers/qsqlodbc.dll

            Why is the odbc plugin in this directory and not where it belongs to (Qt plugins dir) and why do you compile it by yourself when it was already provided by Qt. Remove your self compiled plugin from there and start over. Then the correct one from the Qt sql plugin directory should be picked. Please post the full output of QT_DEBUG_PLUGINS.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            it.aint.meI 1 Reply Last reply
            0
            • hskoglundH Offline
              hskoglundH Offline
              hskoglund
              wrote on last edited by
              #6

              Hi, also to simplify: toss the lambda for the connectButton and do the if (db->open()) { directly after db->setDatabaseName(connectionString);
              (that way there will be no worries re. the lifetime of the db variable)

              1 Reply Last reply
              0
              • it.aint.meI it.aint.me

                Hi.
                I'm using QT 5.15.2 on Win 11 x 64 and trying to connect to the MS SQL Server database. There is a problem with the QODBC driver. When I try to execute db->open() I get the message "Driver not loaded Driver not loaded".

                Here's the code:

                #include "mainwindow.h"
                #include "ui_mainwindow.h"
                #include <QSqlDatabase>
                #include <QSqlError>
                #include <QObject>
                #include <QMessageBox>
                #include <iostream>
                #include <QStringList>
                #include <QDebug>
                #include <QtSql>
                
                MainWindow::MainWindow(QWidget *parent)
                    : QMainWindow(parent)
                    , ui(new Ui::MainWindow)
                {
                    ui->setupUi(this);
                    auto *passEdit = ui->lineEdit;
                    auto *label = ui->label;
                    auto *connectButton = ui->pushButton;
                    QString db_password;
                    QString mes_text = "";
                
                    if (!QSqlDatabase::drivers().contains("QODBC"))
                        mes_text = "not ";
                    QMessageBox::warning(this, "QODBC test", "QODBC driver " + mes_text + "founded");
                
                    //for (auto &Str : QSqlDatabase::drivers())
                    //    std::cout << Str.toStdString() << std::endl;
                
                
                    QSqlDatabase *db = new QSqlDatabase;
                    db->addDatabase("QODBC");
                    QString connectionString = "Driver={SQL Server};";
                    connectionString.append("Server=RS-FS-03,1433;");
                    connectionString.append("Database=TEST_DB;");
                    connectionString.append("Uid=USER;");
                    connectionString.append("Pwd=PASSWORD");
                    db->setDatabaseName(connectionString);
                
                    QObject::connect(passEdit, &QLineEdit::textEdited, [&db_password, passEdit](){db_password = passEdit->text();});
                
                    QObject::connect(connectButton, &QPushButton::clicked, [db, label](){
                        if (db->open()) {
                            label->setText("Connected");
                        }
                        else {
                            label->setText("Not connected");
                            qDebug() << db->lastError().text();
                        }
                    });
                }
                
                MainWindow::~MainWindow()
                {
                    delete ui;
                }
                

                Previously, to install the driver, I ran:
                \Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers>qmake
                \Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers>mingw32-make
                \Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers>mingw32-make install

                and the driver, it seems to me, has been installed.
                I checked in the folder \Qt\5.15.2\mingw81_64\plugins\sqldrivers
                qsqlodbc.dll appeared.
                The list of supported QODBC drivers includes:
                QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
                Please help me solve the problem.

                Ketan__Patel__0011K Offline
                Ketan__Patel__0011K Offline
                Ketan__Patel__0011
                wrote on last edited by
                #7

                @it-aint-me

                Try to install AccessDatabaseEngine Software in your system and Check it.

                if not installed then Follow the link for download
                https://www.microsoft.com/en-us/download/details.aspx?id=54920

                1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @it-aint-me said in QODBC Driver not loaded:

                  Projects/FactoryWorkResults/Slaughter_Results_5-12/build/Desktop_Qt_5_15_2_MinGW_64_bit-Debug/debug/sqldrivers/qsqlodbc.dll

                  Why is the odbc plugin in this directory and not where it belongs to (Qt plugins dir) and why do you compile it by yourself when it was already provided by Qt. Remove your self compiled plugin from there and start over. Then the correct one from the Qt sql plugin directory should be picked. Please post the full output of QT_DEBUG_PLUGINS.

                  it.aint.meI Offline
                  it.aint.meI Offline
                  it.aint.me
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher said in QODBC Driver not loaded:

                  Why is the odbc plugin in this directory and not where it belongs to (Qt plugins dir)

                  I don't know. It appeared after executing mingw32-make install
                  and here too: \Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers
                  It seems strange for me. I thought it should appear in folder \Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers\odbc

                  @Christian-Ehrlicher said in QODBC Driver not loaded:

                  why do you compile it by yourself when it was already provided by Qt.

                  May be, but it didn't work before manual installation. Now it works, but only if I create DSN, and specify it in db.setDatabaseName("USER_DSN");

                  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