Results 1 to 11 of 11

Thread: QSqlDatabase

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QSqlDatabase

    Hi everybody,

    QT:4.1.1
    OS:WinXP
    DB: SQL Server 7.0
    Compiler: MinGW

    I have a small program that are able to connect to a SQL Database via ODBC to our Server.
    The connection works fine. If i write in my login Dialog a false password or user name i get emmediately a Error Message from the Databse, that ok.
    But if i write for "hostname" a host that not exist my program dont respont for 15 seconds, and after that i get the Error Message from the Database.
    So, its possible to set max. 2 seconds for my connection?


    Best Regards
    Think DigitalGasoline

  2. #2
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QSqlDatabase

    Hi everybody!
    Should i explain again my problem
    or i have no chance for solve this problem
    Thanks
    Think DigitalGasoline

  3. #3
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabase

    hm...i think you cant set timeout by own
    a life without programming is like an empty bottle

  4. #4
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QSqlDatabase

    hmmm
    so we will have to live with this problem..
    Think DigitalGasoline

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabase

    From Qt docs:
    void QSqlDatabase::setConnectOptions ( const QString & options = QString() )
    Sets database-specific options. This must be done before the connection is opened or it has no effect (or you can close() the connection, call this function and open() the connection again).
    The format of the options string is a semicolon separated list of option names or option=value pairs. The options depend on the database client used
    Try setting the SQL_ATTR_CONNECTION_TIMEOUT option.

  6. #6
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QSqlDatabase

    Hi Jacek!
    Maybe i have a hope
    but how to set 3 seconds for this Option:
    Qt Code:
    1. db.setConnectOptions("SQL_ATTR_CONNECTION_TIMEOUT");
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabase

    Quote Originally Posted by raphaelf
    but how to set 3 seconds for this Option
    Read carefully my previous post (especially that docs excerpt, which says something about option=value pairs).

  8. #8
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QSqlDatabase

    Hi Jacek!
    I tried this:
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    2. db.setConnectOptions("SQL_ATTR_CONNECTION_TIMEOUT=60");
    3. db.setHostName(host);
    4. db.setDatabaseName("DRIVER={SQL Server};SERVER="+host+";DATABASE=inventar;UID="+user+";PWD="+pass+"");
    5. db.setUserName(user);
    6. db.setPassword(pass);
    7. if(!db.open())
    8. {
    9. QMessageBox::information(this,"",db.lastError().text());
    10. ui.pass_le->clear();
    11. return false;
    12. }
    13. else
    14. {
    15. .
    16. .
    To copy to clipboard, switch view to plain text mode 
    My program try everytime exactly 15 seconds
    What could i try?
    Think DigitalGasoline

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabase

    Then try specifying the SQL_ATTR_LOGIN_TIMEOUT option too.

  10. #10
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QSqlDatabase

    Hi
    I could optimize some seconds (from 22 s. to 7 s)
    I found out that if i set a value between 0 and ..., i get a error after exaclty 7 seconds. Maybe 7 s are the minimum
    Qt Code:
    1. db.setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=5");
    To copy to clipboard, switch view to plain text mode 
    also:
    Qt Code:
    1. db.setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=5;SQL_ATTR_CONNECTION_TIMEOUT=5");
    To copy to clipboard, switch view to plain text mode 

    Thanks to everybody again for the best support
    Think DigitalGasoline

  11. #11
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabase

    Holas
    I was reading this thread and well I noticed that that option works only with ODBC.. and in Qt 4.1...
    isn't a way to avoid the freeze that produces the intent to connect to a unreachable host?

    as I can't use the ones on the documentation from qt 4.1 because I'm using qt 3.1.2 license..
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

Similar Threads

  1. QSqlDatabase, threaded access and locks
    By neuron in forum Qt Programming
    Replies: 2
    Last Post: 4th February 2009, 16:55
  2. QSqlDatabase driver problem
    By croscato in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2008, 17:16
  3. QSqlDatabase connectivity issues
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 16th July 2008, 13:58
  4. GCC can't find QSqlDatabase!!
    By brevleq in forum Qt Programming
    Replies: 5
    Last Post: 29th October 2007, 08:05
  5. Passing around a QSqlDatabase
    By darkadept in forum Qt Programming
    Replies: 2
    Last Post: 8th September 2007, 09: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.