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. MS SQL Server 2008 with Qt
Qt 6.11 is out! See what's new in the release blog

MS SQL Server 2008 with Qt

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 9.9k 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.
  • M Offline
    M Offline
    metRo_
    wrote on last edited by
    #1

    Hi,
    I'm trying to connect Qt to MS SQL Server 2008 R2. I already have compiled the ODBC driver and I think it is ok.
    This is the code I'm using:
    @
    qDebug() << "Drivers: "<<QSqlDatabase::drivers();
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setHostName("ze-w7\SQLExpress");
    db.setDatabaseName("tempdb");
    db.setUserName("sa");
    db.setPassword("123456");
    if(!db.open()){
    qDebug()<<"ERROR: "<<QSqlError(db.lastError()).text();
    } else {
    qDebug()<<"Ok";
    }@

    But I always getting this error:
    Drivers: ("QSQLITE", "QODBC3", "QODBC")
    ERROR: "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"

    What should I do?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mapple
      wrote on last edited by
      #2

      Maybe instead of
      @db.setHostName("ze-w7\SQLExpress");@

      you must write

      @ db.setHostName("ze-w7\SQLExpress");@

      Or try write this code:

      @QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
      db.setDatabaseName("Driver={SQL Server};Server=ze-w7\SQLEXPRESS;Database=tempdb;");
      db.setUserName("sa");
      db.setPassword("123456");
      if(!db.open()){
      qDebug()<<"ERROR: "<<QSqlError(db.lastError()).text();
      } else {
      qDebug()<<"Ok";
      } @

      1 Reply Last reply
      0
      • M Offline
        M Offline
        metRo_
        wrote on last edited by
        #3

        really thanks :)
        Used the code you suggest and works :D

        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