Unable to connect to mssql server from qt application in ubuntu
-
Hello everyone!
Unable to connect to mssql server from qt application in ubuntu 20.04
Sql server located in windows 7
The connection is definitely present, because it was possible to connect through DDbeaver.Can anyone help me in this situation?
Code:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3"); db.setConnectOptions(); QString serverName = "566***"; QString ipName = "tcp:192.168.144.101,1433"; QString dbName = "St***"; QString connectionString = QString("DRIVER={ODBC Driver 18 for SQL Server};Server=%1;Database=%2;").arg(ipName).arg(dbName); db.setDatabaseName(connectionString); db.setUserName("sa"); db.setPassword("top123TOP"); if (db.open()) { qDebug() << "Correct connection"; } else { QString error = db.lastError().text(); qDebug() << error; }
otuput is:
"[Microsoft][ODBC Driver 18 for SQL Server]TCP Provider: Error code 0x2746 [Microsoft][ODBC Driver 18 for SQL Server]Client unable to establish connection QODBC3: Unable to connect"
odbcinst.ini
[ODBC Driver 18 for SQL Server] Description=Microsoft ODBC Driver 18 for SQL Server Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1
-
You should check your connection string e.g. on the command line to see if it's correct.
-
similar answer, not sure if the problem is only with the connection string
./sqlcmd -d StandLD -S 192.168.144.101,1433 -U sa -P top123TOP Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : TCP Provider: Error code 0x2746. Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Client unable to establish connection.
-
@Alexmqueee said in Unable to connect to mssql server from qt application in ubuntu:
ODBC Driver 18 for SQL Server]TCP Provider: Error code 0x2746
No firewall on the SQL Server?
TCP enabled on the SQL Server?
Is the server expecting SSL/TLS and do you have that support on the client side? -
the following solution helped
This was helpful. Ubuntu 20.04 PHP 7.4 using the 19.10 drivers for sqlsrv We have a real old SQL server out there . The SQL Server show's version 10.50.2550.0, i think it's SQL Server 2008 R2. I had to use TLSv1 to connect to the server. I also had to do a "systemctl restart apache2" to get it to take affect. TLSv1.1 did not work with my MSSQL server version. Error message: Connection failed: SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]SSL Provider: [error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol]Database Connection Error edit: /etc/ssl/openssl.cnf 1st line in the file added openssl_conf = default_conf End of file added [default_conf] ssl_conf = ssl_sect [ssl_sect] system_default = system_default_sect [system_default_sect] MinProtocol = TLSv1 CipherString = DEFAULT@SECLEVEL=1 Not 100% sure why i had to restart apache2 for it to take effect, but I had to. systemctl restart apache2 reloaded the page and it works
-
Then please mark this topic as solved, thx.