PDA

View Full Version : removing database



mak_user
2nd June 2011, 14:50
What is wrong with this code. Why I get warning about it?
WARNING: QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.


{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MSAccess};DBQ=E:file.name" );
qDebug() << "DRIVERS :" << QSqlDatabase::drivers();

if (!db.open()) {
qDebug()<< db.lastError().text();
return false;
}
}

if(QSqlDatabase::database().isOpen()) {
qDebug() << "db name :" << QSqlDatabase::database().connectionName();
QSqlDatabase::database().close();
QSqlDatabase::removeDatabase(QSqlDatabase::databas e().connectionName());
}

mak_user
2nd June 2011, 17:28
Should I leave this warning as it is?
Because I need to close connection and open new one to another database.

joyer83
2nd June 2011, 19:07
Do you have any QSqlQuery objects alive when you try to remove the connection? If you have, then that would cause the warning.

DanH
3rd June 2011, 03:03
Yep, you probably have a QSqlQuery object that hasn't passed out of scope and hasn't been clear()ed.