PDA

View Full Version : validate database connection



hoshy
9th April 2009, 13:54
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

spirit
9th April 2009, 14:01
what does this code return?


...
QSqlDatabase db = QSqlDatabase::addDatabase(...);
if (!db.open()) {
qDebug() << db.lastError().text();
return;
}
...

hoshy
9th April 2009, 14:14
Ahh I found the problem...

I was testing it with an empty String, and when I do so the result by calling:

if (!db.open())
qDebug() << db.lastError().text();
...is nothing, because QT opens the connection without any errors. But when I use a wrong String, I get the errortext...

thx