title: How to access SQL server from linux c++ application?
body: <p>We have a Microsoft Sql 2014 database on a remote windows server. I am trying to develop a QT GUI app which connects to this database. The app is in Linux/c++ environment. I tried using QtSql APIs to connect to that database.</p>
  
  <pre><code>bool MainWindow::connect()
  {
      QSqlDatabase db=QSqlDatabase::addDatabase( "QODBC" );//I am not sure if I am calling this correctly
      db.setHostName("III");
  
      db.setDatabaseName("YYY");
      db.setUserName("YYY");
      db.setPassword("XX");
      bool ok = db.open();
      if(ok==true)
      {
          QSqlQuery query;
          query.exec("SELECT * FROM Subjects");
          while (query.next()) 
          {
              int phy = query.value(0).toInt();
              int chem = query.value(1).toInt();
              ui-&gt;lineEdit_2-&gt;setText(QString::number(phy));
              ui-&gt;lineEdit_3-&gt;setText(QString::number(chem));
          }
      }
      else
      {
          qDebug()&lt;&lt;db.lastError();
      }
      return ok;
  }
  </code></pre>
  
  <p>Its giving me error as :</p>
  
  <pre><code>QSqlDatabase: QODBC driver not loaded
  QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
  QSqlError("", "Driver not loaded", "Driver not loaded")
  </code></pre>
  
  <p>I tried exporting the path of sql drivers to my Qt project.Still it didn't work.Then I read some articles and found that I need mssql-tools as well as ODBC Driver on my Linux box. I tried installing this based on this website:</p>
  
  <p><a href="https://blogs.msdn.microsoft.com/sqlnativeclient/2016/10/20/odbc-driver-13-0-for-linux-released/" rel="nofollow noreferrer">https://blogs.msdn.microsoft.com/sqlnativeclient/2016/10/20/odbc-driver-13-0-for-linux-released/</a></p>
  
  <p>and found that this won't work on my linux box (14.04 ubuntu) but only on 15.10 &amp; 16.04. </p>
  
  <pre><code>The following packages have unmet dependencies:
  mssql-tools : 
             Depends: libc6 (&gt;= 2.21) but 2.19-0ubuntu6.9 is to be installed
             Depends: libstdc++6 (&gt;= 5.2) but 4.8.4-2ubuntu1~14.04.3 is to be installed
             Depends: msodbcsql (&gt;= 13.1.0.0) but it is not going to be installed
             Depends: msodbcsql (&lt; 13.2.0.0) but it is not going to be installed
  E: Unable to correct problems, you have held broken packages.
  </code></pre>
  
  <p>Then I used docker from here: 
  <a href="https://hub.docker.com/r/taylorbarrick/mssql-server-linux-tools/" rel="nofollow noreferrer">https://hub.docker.com/r/taylorbarrick/mssql-server-linux-tools/</a>  </p>
  
  <p>I could install it successfully but when I am running    </p>
  
  <pre><code>$docker run -t  taylorbarrick/mssql-server-linux-tools sqlcmd -d &lt;dbname&gt; -H &lt;host&gt; -U &lt;username&gt; -P &lt;password&gt;
  </code></pre>
  
  <p>I am getting errors again.                                     </p>
  
  <pre><code>Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout  expired.
  Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider:    Error code 0x2749.
  Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
  </code></pre>
  
  <p>However,when using visual interface I can connect to sql database.Please help.</p>