Results 1 to 4 of 4

Thread: Qt application connection to microsoft SQL database 2008

  1. #1
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Qt application connection to microsoft SQL database 2008

    Hi,
    I am trying to connect my application to Microsoft SQL Server managment studiio.

    First of all if I do following statement to print drivers.
    Qt Code:
    1. qDebug << QSqlDatabase::drivers();
    To copy to clipboard, switch view to plain text mode 

    It prints "QSQLLITE", "QODBC","QODBC3".

    I have attached file as screenshot to display what database i am trying to connect.

    Now I try to connect

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    2. db.setDatabaseName("db1");
    3. db.setHostName("localhost");
    4. db.setUserName("test");
    5. db.setPassword("test");
    6. bool ok = db.open();
    7.  
    8. if( db.open() )
    9. {
    10. qDebug( "Database successfully opened, now able to query" );
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 
    However my connection fails. I am not quite sure if QDBC3 drivers works fine with Microsoft SQL Server Management studio 2008.

    I have seen at some other posts that lot of other people used syntax like this while setting database name

    Qt Code:
    1. db.setDatabaseName("DRIVER=FreeTDS;SERVER=localhost;Port=1433;DATABASE=db_test;TDS_Version=8.0;uid=SomeUser;pwd=SomePassword");
    To copy to clipboard, switch view to plain text mode 

    Which drivers are compatible with Microsoft SQL Server Management studio 2008.

    If somebody can guide me what i am doing wrong here that would be great?Database.jpgDatabase.jpg
    Last edited by user_mail07; 10th May 2011 at 03:25.

  2. #2
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: Qt application connection to microsoft SQL database 2008

    Can you somebody please help me here? I have attached screenshot to display what database i am trying to connect.

  3. #3
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt application connection to microsoft SQL database 2008

    You haven't tell us which Qt version are you using.

    I've found this bug some time ago.

    If your version is < 4.7.0

    Try changing this ( it works for windows ) :

    Qt Code:
    1. db.setDatabaseName ( "DRIVER={SQL Server};SERVER=localhost;DATABASE=db1" );
    To copy to clipboard, switch view to plain text mode 

    and it must work.

    NOTE : Also, telling us which message error gives to you ( using db.lastError().text() ) would allow to give you a better answer to the problem...

  4. #4
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: Qt application connection to microsoft SQL database 2008

    Now I am getting following error.

    0x00f90c4a " [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"
    Qt version is 4.5.2

Similar Threads

  1. Connection With database
    By sudheer168 in forum Qt Programming
    Replies: 4
    Last Post: 22nd December 2010, 09:18
  2. Database connection
    By poporacer in forum Newbie
    Replies: 7
    Last Post: 7th September 2010, 07:49
  3. Replies: 3
    Last Post: 14th December 2009, 08:38
  4. Replies: 2
    Last Post: 17th April 2009, 22:36
  5. how to connect to a microsoft access database?
    By mismael85 in forum Qt Programming
    Replies: 3
    Last Post: 7th March 2008, 09:25

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.