QT无法从Ubuntu中的QT应用程序连接到MSSQL Server

发布于 2025-02-12 14:42:13 字数 1187 浏览 0 评论 0原文

无法从Ubuntu中的QT应用程序连接到MSSQL Server 20.04 SQL Server位于Windows 7中 连接绝对存在,因为可以通过DDBEAVER连接。

在这种情况下,谁能帮我吗?

代码:

    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是:

"[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


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


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2025-02-19 14:42:16

以下解决方案

对: httpps://github.com/microsoft/microsoft/microsoft/msphpsql/mmsphpsql/11122

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

the following solution helped:

from:https://github.com/microsoft/msphpsql/issues/1112

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文