Results 1 to 3 of 3

Thread: validate database connection

  1. #1
    Join Date
    Apr 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation validate database connection

    Hi folks,

    how can I validate a database connection if the connection has been established correct.

    My problem is... if I set a wrong DatabaseName with setUserName and open the connection with the wrong DatabaseName I get:

    isOpen = true
    isOpenError = false
    isValid = true

    how can that be????

    thx

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: validate database connection

    what does this code return?
    Qt Code:
    1. ...
    2. QSqlDatabase db = QSqlDatabase::addDatabase(...);
    3. if (!db.open()) {
    4. qDebug() << db.lastError().text();
    5. return;
    6. }
    7. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Apr 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: validate database connection

    Ahh I found the problem...

    I was testing it with an empty String, and when I do so the result by calling:
    Qt Code:
    1. if (!db.open())
    2. qDebug() << db.lastError().text();
    To copy to clipboard, switch view to plain text mode 
    ...is nothing, because QT opens the connection without any errors. But when I use a wrong String, I get the errortext...

    thx

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 08:30
  2. cannot share the database connection!!!!
    By cbarmpar in forum Qt Programming
    Replies: 13
    Last Post: 23rd September 2008, 14:42
  3. database connection
    By peace_comp in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2008, 12:16
  4. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 10:22
  5. Qt and MySQL Database Connection
    By shamik in forum Qt Programming
    Replies: 41
    Last Post: 6th October 2006, 12:48

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.