Results 1 to 1 of 1

Thread: [Solved] Using QSqlDatabase - long timeout if no network cornnection

  1. #1
    Join Date
    Oct 2009
    Location
    South Africa
    Posts
    94
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default [Solved] Using QSqlDatabase - long timeout if no network cornnection

    I am using QSqlDatabase to get a connection to 2 databases, a MySQL and MS SQL database.
    I am trying to do some error checking for when it loses network connection, and thus cannot connect to the database.
    With the MySQL database, it timeout very quickly before returning an error that it can't connect, but with the Microsoft SQL database, it takes quite a few seconds before it responds (gives the impression of hanging)
    Is there any way for me to configure the connection options to shorten the timeout comparable to the MySQL connection?

    This is my code for the MS SQL class...

    Qt Code:
    1. {
    2. m_ConnectionName = cname;
    3. db = QSqlDatabase::addDatabase("QODBC", m_ConnectionName);
    4. db.setDatabaseName("DRIVER={SQL Server};Server="+host+";Database="+dbase+";Uid="+user+";Pwd="+pw+";WSID=");
    5. db.open();
    6.  
    7. m_LastError = db.lastError().text();
    8. if (!db.isOpen()) {
    9. db.setConnectOptions(); //clears connect options string
    10. m_DBOpen = false;
    11. }
    12. else
    13. m_DBOpen = true;
    14. }
    To copy to clipboard, switch view to plain text mode 


    Added after 1 12 minutes:


    Thanks, I seem to have figured it out, I use the following:

    Qt Code:
    1. db.setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=2");
    To copy to clipboard, switch view to plain text mode 
    Last edited by ShamusVW; 25th July 2016 at 12:57.

Similar Threads

  1. Replies: 2
    Last Post: 7th November 2015, 09:49
  2. QSqlDatabase best practices with long-running application
    By redBeard in forum Qt Programming
    Replies: 6
    Last Post: 17th October 2011, 19:32
  3. QSqlDatabase connection timeout?
    By joseprl89 in forum Qt Programming
    Replies: 6
    Last Post: 27th March 2011, 01:43
  4. QSqlDatabase Mysql timeout versus PortScanner
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2008, 00:08
  5. QSqlDatabase Time out no network to long....
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2007, 00:41

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.