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. QT with ODBC Driver cant connect to MSSQL
Qt 6.11 is out! See what's new in the release blog

QT with ODBC Driver cant connect to MSSQL

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 8.7k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    Prosit
    wrote on last edited by
    #1

    I have developed part of a database manager in QT and it all works fine, i can read tables and show its data, remove rows etc.
    BUT now i try to continue developing this program on a different computer it all breaks down. I can compile the project just fine, there is no errors, however when i run it and try to connect to the database the program feezes for a about 20seconds(im guessing its trying to connect for a while) then it comes back to life and was unable to connect. The message i get from QSqlDatabase::lastError() is: "[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). QODBC3: Unable to connect"

    I am sure that the server exists and that i have access because i can use the MSSQL management studio to connect without problems. On the new computer i have compiled the ODBC driver from the same QT source as on the first and i can see that the QODBC driver is available.

    I'm all out of ideas on this and i would love some help.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      francomartins
      wrote on last edited by
      #2

      Example of SQL Server Conection :

      @
      QString ipserver,LoginName,database,Pass;
      QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "MyDatabase");

      db.setDatabaseName("DRIVER={SQL Server};Server="+ipserver+";Database="+database+";Uid="+LoginName+";Port=1433;Pwd="+Pass+";WSID=");

      if(db.open())
      {
      qDebug() << "Opened";
      db.close();
      }
      else
      qDebug() << "Error" << db.lastError().text();@

      the WSID =. “is used to hide the client machine to the database server log ,is optional .

      1 Reply Last reply
      0

      • Login

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