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. Unable to connect to mssql server from qt application in ubuntu
Forum Updated to NodeBB v4.3 + New Features

Unable to connect to mssql server from qt application in ubuntu

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 4.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.
  • A Offline
    A Offline
    Alexmqueee
    wrote on 1 Jul 2022, 06:03 last edited by
    #1

    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
    
    
    
    1 Reply Last reply
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 1 Jul 2022, 06:25 last edited by
      #2

      You should check your connection string e.g. on the command line to see if it's correct.

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alexmqueee
        wrote on 1 Jul 2022, 06:33 last edited by
        #3

        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.
        
        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on 1 Jul 2022, 06:58 last edited by
          #4

          @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?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Alexmqueee
            wrote on 1 Jul 2022, 07:15 last edited by
            #5

            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
            

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

            1 Reply Last reply
            1
            • C Online
              C Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 1 Jul 2022, 07:17 last edited by
              #6

              Then please mark this topic as solved, thx.

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

              1 Reply Last reply
              0

              1/6

              1 Jul 2022, 06:03

              • Login

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