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. "SSL connection error: unknown error number QMYSQL: Unable to connect"
Forum Update on Monday, May 27th 2025

"SSL connection error: unknown error number QMYSQL: Unable to connect"

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 5 Posters 3.4k 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.
  • D Offline
    D Offline
    DeadSo0ul
    wrote on 28 Dec 2023, 16:29 last edited by
    #1

    Hello,
    I am trying to connect my windows pc to an azure mysql database server.
    I have this databaseconnection class where I connect the application to the databse:

    #include "databaseconnection.h"
    QSqlDatabase databaseConnection::db;
    
    QSqlDatabase databaseConnection::getDatabase() {
        return db;
    }
    
    bool databaseConnection::openConnection() {
    
        db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("sql-900.mysql.database.azure.com");
        db.setDatabaseName("qt");
        db.setUserName("sqladmin");
        db.setPassword("password");
    
        if (db.open()) {
            return true;
        } else {
            // Handle connection error
            return false;
        }
    }
    
    void databaseConnection::closeConnection() {
        db.close();
    }
    
    

    This same code worked the same on my mac machine but won't work on my windows machine. The error I get when the user tries to connect is following: "SSL connection error: unknown error number QMYSQL: Unable to connect".

    I tried disabling "require_secure_transport" from my azure server parameters which didn't do anything.

    Any help would be appreciated.
    Thanks!

    J S 2 Replies Last reply 28 Dec 2023, 18:43
    0
    • D DeadSo0ul
      28 Dec 2023, 16:29

      Hello,
      I am trying to connect my windows pc to an azure mysql database server.
      I have this databaseconnection class where I connect the application to the databse:

      #include "databaseconnection.h"
      QSqlDatabase databaseConnection::db;
      
      QSqlDatabase databaseConnection::getDatabase() {
          return db;
      }
      
      bool databaseConnection::openConnection() {
      
          db = QSqlDatabase::addDatabase("QMYSQL");
          db.setHostName("sql-900.mysql.database.azure.com");
          db.setDatabaseName("qt");
          db.setUserName("sqladmin");
          db.setPassword("password");
      
          if (db.open()) {
              return true;
          } else {
              // Handle connection error
              return false;
          }
      }
      
      void databaseConnection::closeConnection() {
          db.close();
      }
      
      

      This same code worked the same on my mac machine but won't work on my windows machine. The error I get when the user tries to connect is following: "SSL connection error: unknown error number QMYSQL: Unable to connect".

      I tried disabling "require_secure_transport" from my azure server parameters which didn't do anything.

      Any help would be appreciated.
      Thanks!

      J Offline
      J Offline
      JonB
      wrote on 28 Dec 2023, 18:43 last edited by
      #2

      @DeadSo0ul
      Do you have SSL support installed on the Mac but not the PC? What version?

      1 Reply Last reply
      0
      • D DeadSo0ul
        28 Dec 2023, 16:29

        Hello,
        I am trying to connect my windows pc to an azure mysql database server.
        I have this databaseconnection class where I connect the application to the databse:

        #include "databaseconnection.h"
        QSqlDatabase databaseConnection::db;
        
        QSqlDatabase databaseConnection::getDatabase() {
            return db;
        }
        
        bool databaseConnection::openConnection() {
        
            db = QSqlDatabase::addDatabase("QMYSQL");
            db.setHostName("sql-900.mysql.database.azure.com");
            db.setDatabaseName("qt");
            db.setUserName("sqladmin");
            db.setPassword("password");
        
            if (db.open()) {
                return true;
            } else {
                // Handle connection error
                return false;
            }
        }
        
        void databaseConnection::closeConnection() {
            db.close();
        }
        
        

        This same code worked the same on my mac machine but won't work on my windows machine. The error I get when the user tries to connect is following: "SSL connection error: unknown error number QMYSQL: Unable to connect".

        I tried disabling "require_secure_transport" from my azure server parameters which didn't do anything.

        Any help would be appreciated.
        Thanks!

        S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 28 Dec 2023, 19:46 last edited by
        #3

        @DeadSo0ul hi,

        Did you install the OpenSSL dlls ? (You can do that through the maintenance tool).

        @JonB macOS provides native APIs for secure communication since the beginning while Windows has started only recently.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 1 Reply Last reply 28 Dec 2023, 21:18
        1
        • S SGaist
          28 Dec 2023, 19:46

          @DeadSo0ul hi,

          Did you install the OpenSSL dlls ? (You can do that through the maintenance tool).

          @JonB macOS provides native APIs for secure communication since the beginning while Windows has started only recently.

          D Offline
          D Offline
          DeadSo0ul
          wrote on 28 Dec 2023, 21:18 last edited by
          #4

          @SGaist
          Thanks for your reply!
          I did install the OpenSSL 3.0.12 Toolkit after your commentScreenshot 2023-12-28 231535.png
          but the error still remains the same :
          "SSL connection error: unknown error number QMYSQL: Unable to connect"

          S 1 Reply Last reply 29 Dec 2023, 20:35
          0
          • D DeadSo0ul
            28 Dec 2023, 21:18

            @SGaist
            Thanks for your reply!
            I did install the OpenSSL 3.0.12 Toolkit after your commentScreenshot 2023-12-28 231535.png
            but the error still remains the same :
            "SSL connection error: unknown error number QMYSQL: Unable to connect"

            S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 29 Dec 2023, 20:35 last edited by
            #5

            @DeadSo0ul is the path to the OpenSSL dlls part of the PATH environment variable for your application ? Check the Run part of the project panel.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            D 1 Reply Last reply 31 Dec 2023, 14:53
            1
            • S SGaist
              29 Dec 2023, 20:35

              @DeadSo0ul is the path to the OpenSSL dlls part of the PATH environment variable for your application ? Check the Run part of the project panel.

              D Offline
              D Offline
              DeadSo0ul
              wrote on 31 Dec 2023, 14:53 last edited by
              #6

              @SGaist
              I added OpenSSl dll libraries to the PATH environment

              Screenshot 2023-12-31 165050.png

              But the error still remains. I also tried to add

              C:\Qt\Tools\OpenSSLv3\Win_x64
              

              but that still didn't work.

              S piervalliP 2 Replies Last reply 31 Dec 2023, 19:40
              0
              • D DeadSo0ul
                31 Dec 2023, 14:53

                @SGaist
                I added OpenSSl dll libraries to the PATH environment

                Screenshot 2023-12-31 165050.png

                But the error still remains. I also tried to add

                C:\Qt\Tools\OpenSSLv3\Win_x64
                

                but that still didn't work.

                S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 31 Dec 2023, 19:40 last edited by
                #7

                @DeadSo0ul From the image you posted, you seem to have created a new environment variable. Is that so ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                D 1 Reply Last reply 1 Jan 2024, 10:45
                0
                • D DeadSo0ul
                  31 Dec 2023, 14:53

                  @SGaist
                  I added OpenSSl dll libraries to the PATH environment

                  Screenshot 2023-12-31 165050.png

                  But the error still remains. I also tried to add

                  C:\Qt\Tools\OpenSSLv3\Win_x64
                  

                  but that still didn't work.

                  piervalliP Offline
                  piervalliP Offline
                  piervalli
                  wrote on 31 Dec 2023, 20:34 last edited by
                  #8

                  @DeadSo0ul
                  Copy the DLL in same folder of the excutable (debug and release)

                  1 Reply Last reply
                  0
                  • S SGaist
                    31 Dec 2023, 19:40

                    @DeadSo0ul From the image you posted, you seem to have created a new environment variable. Is that so ?

                    D Offline
                    D Offline
                    DeadSo0ul
                    wrote on 1 Jan 2024, 10:45 last edited by
                    #9

                    @SGaist
                    I think so.
                    Did I misunderstood?

                    I also tried what @piervalli suggested:
                    copying and pasting the .dll files to the folder that is my executable in
                    but without any success.

                    piervalliP S 2 Replies Last reply 1 Jan 2024, 13:50
                    0
                    • D DeadSo0ul
                      1 Jan 2024, 10:45

                      @SGaist
                      I think so.
                      Did I misunderstood?

                      I also tried what @piervalli suggested:
                      copying and pasting the .dll files to the folder that is my executable in
                      but without any success.

                      piervalliP Offline
                      piervalliP Offline
                      piervalli
                      wrote on 1 Jan 2024, 13:50 last edited by
                      #10

                      @DeadSo0ul

                      What is version of Qt?
                      For 5.15.2 it uses openssl v1 instead for Qt6 openssl3

                      D 1 Reply Last reply 1 Jan 2024, 14:02
                      0
                      • piervalliP piervalli
                        1 Jan 2024, 13:50

                        @DeadSo0ul

                        What is version of Qt?
                        For 5.15.2 it uses openssl v1 instead for Qt6 openssl3

                        D Offline
                        D Offline
                        DeadSo0ul
                        wrote on 1 Jan 2024, 14:02 last edited by
                        #11

                        @piervalli
                        QT Creator: 12.0.1
                        Qt: 6.6.0

                        I installed OpenSSL from their official site: https://www.openssl.org/source/.

                        I also tried the .dll files from the tools folder in the qt folder.

                        piervalliP 1 Reply Last reply 1 Jan 2024, 17:00
                        0
                        • D DeadSo0ul
                          1 Jan 2024, 14:02

                          @piervalli
                          QT Creator: 12.0.1
                          Qt: 6.6.0

                          I installed OpenSSL from their official site: https://www.openssl.org/source/.

                          I also tried the .dll files from the tools folder in the qt folder.

                          piervalliP Offline
                          piervalliP Offline
                          piervalli
                          wrote on 1 Jan 2024, 17:00 last edited by
                          #12

                          @DeadSo0ul

                          You need understand if the library is loaded,
                          (This is usually test that I use for 5.15)

                          qDebug() << QSslSocket::supportsSsl() <<QSslSocket::sslLibraryBuildVersionString() << QSslSocket::sslLibraryVersionString()
                          
                          D 1 Reply Last reply 1 Jan 2024, 21:20
                          1
                          • D DeadSo0ul
                            1 Jan 2024, 10:45

                            @SGaist
                            I think so.
                            Did I misunderstood?

                            I also tried what @piervalli suggested:
                            copying and pasting the .dll files to the folder that is my executable in
                            but without any success.

                            S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 1 Jan 2024, 20:02 last edited by
                            #13

                            @DeadSo0ul said in "SSL connection error: unknown error number QMYSQL: Unable to connect":

                            @SGaist
                            I think so.
                            Did I misunderstood?

                            Yes, I wrote that you should add the path to the PATH environment variable. Not create a new one.

                            By the way, the Qt maintenance tool offers to download a pre-built version of OpenSSL, I would recommend using that one.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            D 1 Reply Last reply 1 Jan 2024, 21:31
                            0
                            • piervalliP piervalli
                              1 Jan 2024, 17:00

                              @DeadSo0ul

                              You need understand if the library is loaded,
                              (This is usually test that I use for 5.15)

                              qDebug() << QSslSocket::supportsSsl() <<QSslSocket::sslLibraryBuildVersionString() << QSslSocket::sslLibraryVersionString()
                              
                              D Offline
                              D Offline
                              DeadSo0ul
                              wrote on 1 Jan 2024, 21:20 last edited by
                              #14

                              @piervalli said in "SSL connection error: unknown error number QMYSQL: Unable to connect":

                              eed understand if the library is loaded,
                              (This is usually test that I use for 5.15)

                              I get a positive result for loading the library:

                              true "OpenSSL 3.0.7 1 Nov 2022" "OpenSSL 3.2.0 23 Nov 2023
                              
                              piervalliP 1 Reply Last reply 1 Jan 2024, 22:48
                              0
                              • S SGaist
                                1 Jan 2024, 20:02

                                @DeadSo0ul said in "SSL connection error: unknown error number QMYSQL: Unable to connect":

                                @SGaist
                                I think so.
                                Did I misunderstood?

                                Yes, I wrote that you should add the path to the PATH environment variable. Not create a new one.

                                By the way, the Qt maintenance tool offers to download a pre-built version of OpenSSL, I would recommend using that one.

                                D Offline
                                D Offline
                                DeadSo0ul
                                wrote on 1 Jan 2024, 21:31 last edited by
                                #15

                                @SGaist
                                I understood this time and added

                                C:\Program Files\OpenSSL-Win64
                                

                                as well as

                                C:\Qt\Tools\OpenSSLv3\Win_x64
                                

                                to the Path variable.
                                That gave no result.

                                1 Reply Last reply
                                0
                                • D DeadSo0ul
                                  1 Jan 2024, 21:20

                                  @piervalli said in "SSL connection error: unknown error number QMYSQL: Unable to connect":

                                  eed understand if the library is loaded,
                                  (This is usually test that I use for 5.15)

                                  I get a positive result for loading the library:

                                  true "OpenSSL 3.0.7 1 Nov 2022" "OpenSSL 3.2.0 23 Nov 2023
                                  
                                  piervalliP Offline
                                  piervalliP Offline
                                  piervalli
                                  wrote on 1 Jan 2024, 22:48 last edited by piervalli 1 Feb 2024, 08:29
                                  #16

                                  @DeadSo0ul
                                  Please check on Azure what is the minimum version of TLS supported. Some versions es 1.0 or 1.1 are declared by Microsoft deprecated.

                                  https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/tls-support

                                  I think the mistage is tls version, in the documentation of driver
                                  https://doc.qt.io/qt-6/sql-driver.html#qmysql
                                  we have the flag MYSQL_OPT_TLS_VERSION
                                  ( I never tested is only an idea)

                                  D 1 Reply Last reply 2 Jan 2024, 08:55
                                  0
                                  • piervalliP piervalli
                                    1 Jan 2024, 22:48

                                    @DeadSo0ul
                                    Please check on Azure what is the minimum version of TLS supported. Some versions es 1.0 or 1.1 are declared by Microsoft deprecated.

                                    https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/tls-support

                                    I think the mistage is tls version, in the documentation of driver
                                    https://doc.qt.io/qt-6/sql-driver.html#qmysql
                                    we have the flag MYSQL_OPT_TLS_VERSION
                                    ( I never tested is only an idea)

                                    D Offline
                                    D Offline
                                    DeadSo0ul
                                    wrote on 2 Jan 2024, 08:55 last edited by
                                    #17

                                    @piervalli
                                    The current tls version is 1.2 with an option to enable 1.3

                                    Screenshot 2024-01-02 at 10.53.12 AM.png

                                    How can I set that MYSQL_OPT_TLS_VERSION to 1.2 or possibly 1.3

                                    piervalliP 1 Reply Last reply 2 Jan 2024, 11:25
                                    0
                                    • D DeadSo0ul
                                      2 Jan 2024, 08:55

                                      @piervalli
                                      The current tls version is 1.2 with an option to enable 1.3

                                      Screenshot 2024-01-02 at 10.53.12 AM.png

                                      How can I set that MYSQL_OPT_TLS_VERSION to 1.2 or possibly 1.3

                                      piervalliP Offline
                                      piervalliP Offline
                                      piervalli
                                      wrote on 2 Jan 2024, 11:25 last edited by piervalli 1 Feb 2024, 11:25
                                      #18

                                      @DeadSo0ul

                                      Try with

                                        db.setConnectOptions(QLatin1String("MYSQL_OPT_TLS_VERSION=TLSv1.2"))
                                      

                                      Before db.open()

                                      D 1 Reply Last reply 4 Jan 2024, 10:52
                                      0
                                      • piervalliP piervalli
                                        2 Jan 2024, 11:25

                                        @DeadSo0ul

                                        Try with

                                          db.setConnectOptions(QLatin1String("MYSQL_OPT_TLS_VERSION=TLSv1.2"))
                                        

                                        Before db.open()

                                        D Offline
                                        D Offline
                                        DeadSo0ul
                                        wrote on 4 Jan 2024, 10:52 last edited by
                                        #19

                                        Hi @piervalli
                                        I tried adding db.setConnectOptions(QLatin1String("MYSQL_OPT_TLS_VERSION=TLSv1.2"));
                                        I get these two errors:
                                        QMYSQLDriver::open: Illegal connect option value 'MYSQL_OPT_TLS_VERSION=TLSv1.2'
                                        and
                                        QSqlError("2026", "QMYSQL: Unable to connect", "SSL connection error: unknown error number")

                                        I will provide the whole .cpp file in case I am doing something wrong

                                        #include "databasemanager.hpp"
                                        #include <QSslSocket>
                                        DatabaseManager::DatabaseManager() {
                                        
                                        }
                                        
                                        QSqlDatabase DatabaseManager::getDatabase() {
                                            return db;
                                        }
                                        
                                        void DatabaseManager::openConnection() {
                                            db = QSqlDatabase::addDatabase("QMYSQL");
                                            db.setHostName("name.mysql.database.azure.com");
                                            db.setPort(3306);  // Default MySQL port
                                            db.setDatabaseName("db");
                                            db.setUserName("admin");
                                            db.setPassword("admin");
                                            db.setConnectOptions(QLatin1String("MYSQL_OPT_TLS_VERSION=TLSv1.2"));
                                        
                                            if (db.open() && db.isOpen()) {
                                                qDebug() << "Database opened successfully";
                                            } else {
                                                // Handle connection error
                                                qDebug() << "Database failed to open";
                                                qDebug() << db.lastError();
                                                qDebug() << QSslSocket::supportsSsl() <<QSslSocket::sslLibraryBuildVersionString() << QSslSocket::sslLibraryVersionString();
                                        
                                        
                                            }
                                        }
                                        
                                        void DatabaseManager::closeConnection() {
                                            db.close();
                                        }
                                        
                                        
                                        1 Reply Last reply
                                        0
                                        • hskoglundH Offline
                                          hskoglundH Offline
                                          hskoglund
                                          wrote on 4 Jan 2024, 11:41 last edited by
                                          #20

                                          Hi sometimes those setConnectionOptions() need a trailling semicolon, maybe try:

                                          db.setConnectOptions("MYSQL_OPT_TLS_VERSION=TLSv1.2;");
                                          
                                          1 Reply Last reply
                                          0

                                          1/22

                                          28 Dec 2023, 16:29

                                          • Login

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