Results 1 to 2 of 2

Thread: How to connect to ms sql server 2008 EXPRESS?

  1. #1
    Join Date
    Mar 2007
    Posts
    7
    Thanks
    1

    Default How to connect to ms sql server 2008 EXPRESS?

    the code:
    Qt Code:
    1. QString error;
    2. QString conn = "Data Source=.\\SQLEXPRESS;Initial Catalog=master;Integrated Security=False;Persist Security Info=False;"
    3. "User ID=sa;password=[]";
    4.  
    5. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "MainDBConnection");
    6. db.setDatabaseName(conn);
    7. db.setUserName("sa");
    8. db.setPassword("[]");
    9.  
    10. if (!db.open())
    11. error = db.lastError().text();
    To copy to clipboard, switch view to plain text mode 

    but it not works, error == "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"

    while following run, when i use mssql 2005 enterprise edition.
    Qt Code:
    1. conn = QString::fromLocal8Bit("DRIVER={SQL SERVER};SERVER=192.168.10.96;DATABASE=master;Uid=sa;Pwd=[]");
    2. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "MainDBConnection");
    3. db.setDatabaseName(conn);
    4. db.setUserName("sa");
    5. db.setPassword("[]");
    To copy to clipboard, switch view to plain text mode 
    thx!

  2. #2
    Join Date
    Apr 2010
    Location
    United States
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to connect to ms sql server 2008 EXPRESS?

    If you want to use a ODBC connection you'll need to define a DSN and then pass the name of the DSN to setDatabaseName before opening ... you don't need the classic connection string.

    For example:
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "MainDBConnection");
    2. db.setDatabaseName("dsnname"); // define DSN in your /etc/odbc.ini on unix or through ODBC wizard in control panel on windows
    3. // user and pass not needed if you define these in DSN or use windows authentication
    4. db.setUserName("sa");
    5. db.setPassword("sapass");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QT 4.4 setup help with VC++ 2008 Express
    By Chronos in forum Installation and Deployment
    Replies: 5
    Last Post: 21st July 2009, 19:40
  2. how to compile with msvc express 2008
    By john_god in forum Installation and Deployment
    Replies: 4
    Last Post: 22nd March 2009, 14:09
  3. Qt 4.5.0 vs MSVS 2008 Express Edition
    By Rainstorm in forum Installation and Deployment
    Replies: 5
    Last Post: 21st March 2009, 00:11
  4. msvc++ 2008 express and msvc++ 2005 express
    By vonCZ in forum Installation and Deployment
    Replies: 4
    Last Post: 9th December 2008, 12:15
  5. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 14:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.