kornicameister
29th October 2010, 23:11
After I've read something like 40 threads in this forum and the docs I failed to find correctly-working solution for my problem with disconnection from DB
I constantly have this output when disconnection takes place
QSqlDatabasePrivate::removeDatabase: connection 'my_connection' is still in use, all queries will cease to work.
here is my code which I assume is written like wysota proposed in one of thread I'h read
void ConnectionQuery::connect(QString connName, ConnectionType cType){
QSqlDatabase database = QSqlDatabase::addDatabase("QMYSQL",cD.data()->getConnectionName());
if(cD->getConnectionName() == connName){
qDebug() << ("ConnectionQuery::connect() - connName argument and connectionName from ConnectioData are the same");
}
database.setUserName(this->cD.data()->getUser());
database.setPassword(this->cD.data()->getPass());
database.setHostName(this->cD.data()->getHost());
database.setPort(this->cD.data()->getPort());
database.setDatabaseName(this->cD.data()->getConnectionName());
if(!database.open()){
qErrnoWarning("ConnectionQuery::connect() - connecting failed");
cStatus = database.lastError().text();
}else{
QString tmp("Połączony z bazą danych ");
tmp.append(cD.data()->getConnectionName());
cStatus = codec->toUnicode(tmp.toLatin1());
}
}
void ConnectionQuery::disconnect(){
QSqlDatabase database = QSqlDatabase::database(connectionName);
database.close();
QSqlDatabase::removeDatabase(this->connectionName);
cStatus = codec->toUnicode("Rozłączony z bazą danych");
}
Yet the warning is still present, or rather maybe exception is still here :confused:
I constantly have this output when disconnection takes place
QSqlDatabasePrivate::removeDatabase: connection 'my_connection' is still in use, all queries will cease to work.
here is my code which I assume is written like wysota proposed in one of thread I'h read
void ConnectionQuery::connect(QString connName, ConnectionType cType){
QSqlDatabase database = QSqlDatabase::addDatabase("QMYSQL",cD.data()->getConnectionName());
if(cD->getConnectionName() == connName){
qDebug() << ("ConnectionQuery::connect() - connName argument and connectionName from ConnectioData are the same");
}
database.setUserName(this->cD.data()->getUser());
database.setPassword(this->cD.data()->getPass());
database.setHostName(this->cD.data()->getHost());
database.setPort(this->cD.data()->getPort());
database.setDatabaseName(this->cD.data()->getConnectionName());
if(!database.open()){
qErrnoWarning("ConnectionQuery::connect() - connecting failed");
cStatus = database.lastError().text();
}else{
QString tmp("Połączony z bazą danych ");
tmp.append(cD.data()->getConnectionName());
cStatus = codec->toUnicode(tmp.toLatin1());
}
}
void ConnectionQuery::disconnect(){
QSqlDatabase database = QSqlDatabase::database(connectionName);
database.close();
QSqlDatabase::removeDatabase(this->connectionName);
cStatus = codec->toUnicode("Rozłączony z bazą danych");
}
Yet the warning is still present, or rather maybe exception is still here :confused: