"SSL connection error: unknown error number QMYSQL: Unable to connect"
-
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! -
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!@DeadSo0ul
Do you have SSL support installed on the Mac but not the PC? What version? -
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!@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.
-
@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.
-
@SGaist
Thanks for your reply!
I did install the OpenSSL 3.0.12 Toolkit after your comment
but the error still remains the same :
"SSL connection error: unknown error number QMYSQL: Unable to connect"@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.
-
@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.
-
@SGaist
I added OpenSSl dll libraries to the PATH environmentBut the error still remains. I also tried to add
C:\Qt\Tools\OpenSSLv3\Win_x64
but that still didn't work.
@DeadSo0ul From the image you posted, you seem to have created a new environment variable. Is that so ?
-
@SGaist
I added OpenSSl dll libraries to the PATH environmentBut the error still remains. I also tried to add
C:\Qt\Tools\OpenSSLv3\Win_x64
but that still didn't work.
@DeadSo0ul
Copy the DLL in same folder of the excutable (debug and release) -
@DeadSo0ul From the image you posted, you seem to have created a new environment variable. Is that so ?
-
@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.What is version of Qt?
For 5.15.2 it uses openssl v1 instead for Qt6 openssl3 -
What is version of Qt?
For 5.15.2 it uses openssl v1 instead for Qt6 openssl3@piervalli
QT Creator: 12.0.1
Qt: 6.6.0I 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.
-
@piervalli
QT Creator: 12.0.1
Qt: 6.6.0I 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.
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()
-
@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.@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.
-
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()
@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
-
@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.
-
@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
@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) -
@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)@piervalli
The current tls version is 1.2 with an option to enable 1.3How can I set that MYSQL_OPT_TLS_VERSION to 1.2 or possibly 1.3
-
@piervalli
The current tls version is 1.2 with an option to enable 1.3How can I set that MYSQL_OPT_TLS_VERSION to 1.2 or possibly 1.3
Try with
db.setConnectOptions(QLatin1String("MYSQL_OPT_TLS_VERSION=TLSv1.2"))
Before db.open()
-
Try with
db.setConnectOptions(QLatin1String("MYSQL_OPT_TLS_VERSION=TLSv1.2"))
Before db.open()
Hi @piervalli
I tried addingdb.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(); }