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. Connecting to MS SQL Server 2012 from Mac OS X Mavericks

Connecting to MS SQL Server 2012 from Mac OS X Mavericks

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.9k 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.
  • C Offline
    C Offline
    charliebounce
    wrote on 19 Sept 2014, 18:09 last edited by
    #1

    Hi Everyone,

    I have searched the forum for an answer to this question but I can't seem to find one. I am trying to connect to a Microsoft SQL Database 2012 server fro Mac OS X Mavericks 10.9.4 as shown below but I don't know what to substitute for "DRIVER={SQL Native Client}":

    [code]
    #include <QCoreApplication>
    #include <QtSql>
    #include <QDebug>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    QString serverName = "192.168.1.67\\MSSQLSERVER";
    QString dbName = "AdventureWorks2012";
    
    
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setConnectOptions();
    
    QString dsn = QString("DRIVER={SQL Native Client}; SERVER=%1; DATABASE=%2; UID=SA; PWD=******;").arg(serverName).arg(dbName);
    
    
    db.setDatabaseName(dsn);
    
    if(db.open()){
        qDebug() << "Connected";
        db.close();
    }
    else
    {
        qDebug() << "Errors = " << db.lastError();
    }
    
    return a.exec&#40;&#41;;
    

    }

    [/code]

    1 Reply Last reply
    0
    • H Online
      H Online
      hskoglund
      wrote on 19 Sept 2014, 23:14 last edited by
      #2

      Hi, it's possible for sure, but not as straightforward as on Windows. While you'll use the same Qt classes, like QSqlDatabase etc. you need to install ODBC support on your Mavericks system. I did this earlier this year and wrote a "DB library module ":https://github.com/Clinware/CWDB/blob/master/CWDB.cpp with Qt that works both in Windows and Mac.

      On Windows you just can call setDatabaseName() and open(), as in your example above, but on Mavericks you'll first need to create 2 conf files: "/Users/username/Library/ODBC/odbc.ini" and "/Users/username/.freetds.conf" (as you see in my Github code).

      So what you need to install: /usr/lib/libiodbc.2.dylib (this is what Qt's DLL libqsqlodbc.dylib wants, if you do otool -L on it) and /usr/local/lib/libtdsodbc.0.so (as requested by the odbc.ini file you create).

      The first one is usually default installed even on Mavericks I think... Anyway you got some leads here :-)

      1 Reply Last reply
      0

      1/2

      19 Sept 2014, 18:09

      • Login

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