Results 1 to 7 of 7

Thread: Connect To Sql Server With QT

  1. #1
    Join Date
    Oct 2011
    Posts
    36
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Connect To Sql Server With QT

    Hi
    How I Connect To SQL Server DataBase With QT
    (I Tested QODBC)But Driver Not Loaded
    Thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Connect To Sql Server With QT

    QODBC for Open Database Connectivity (ODBC)
    Make sure the ODBC plugin is built and present on your machine: is should show in the output of QSqlDatabase::drivers().
    Make sure a suitable SQL Server ODBC driver is installed on your machine.
    Make sure your ODBC DSN is set up/correct.

    Only the first point has much to do with Qt.

  3. #3
    Join Date
    Sep 2011
    Posts
    20
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Connect To Sql Server With QT

    Hello Metor,
    First of all you need to check that respective Qt odbc driver is available or not on path "C:\Qt\2010.05\qt\plugins\sqldrivers".At this path following file shoulb be present to make connectivity with sql server DB.
    libqsqlodbc4.a
    libqsqlodbcd4.a
    qsqlodbc4.dll
    qsqlodbcd4.dll

    If above files are not present then you need to build odbc driver for your QT and after that you need to create DSN for your odbc driver.

  4. #4
    Join Date
    Oct 2011
    Posts
    36
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Connect To Sql Server With QT

    Thanks For All But How I Do That

  5. #5
    Join Date
    Sep 2011
    Posts
    20
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Connect To Sql Server With QT

    Use Below code to check DB connectivity If driver is not present then it will throw the error.
    bool createConnection()
    {
    QSqlDatabase db = QSqlDatabase::addDatabase("DSNName");
    db.setHostName("SystemHostName");
    db.setDatabaseName("DSNName");
    db.setUserName("DBUserName");
    db.setPassword("UrDBpassword");

    //Checking DB connection
    if(!db.open())
    {
    QMessageBox::critical(0,QObject::tr("DATABASE OPEN"),db.lastError().text());
    return false;
    }


    return true;
    }
    Last edited by lekhrajdeshmukh; 12th December 2011 at 05:09.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Connect To Sql Server With QT

    Quote Originally Posted by METEOR7 View Post
    Thanks For All But How I Do That
    How do you do what? Check that the Qt driver plugin exists, build the Qt plugin, check that a suitable MS SQL Server ODBC driver exists, build a suitable ODBC DSN, check that the connection is working...?

    The first two items are covered in my last post and the page I linked to.

  7. #7
    Join Date
    Oct 2011
    Posts
    36
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Connect To Sql Server With QT

    How I Build Plugin Please Explain Details

    Thanks

Similar Threads

  1. How to automaticaly connect client to server
    By sksingh73 in forum Newbie
    Replies: 1
    Last Post: 4th July 2010, 20:08
  2. program cannot connect to X server
    By Wazman in forum Qt Programming
    Replies: 3
    Last Post: 1st September 2009, 19:28
  3. Trying to Connect To SQL Server 2005
    By rossd in forum Installation and Deployment
    Replies: 0
    Last Post: 6th March 2009, 19:56
  4. cannot connect to X server
    By jcr in forum Qt Programming
    Replies: 1
    Last Post: 18th April 2007, 14:22
  5. connect to sql server
    By raphaelf in forum Qt Programming
    Replies: 15
    Last Post: 27th February 2006, 18:06

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.