QSqlDatabase Connection Close on Destruction
I'm wondering if anyone has else has seen this issue when using Qt to connect to a MS SQL database. The connection is opened fine and I am able to access data without issues, however, when the application terminates (and thus, the QSqlDatabases that were constructed through addDatabase are destroyed) I get this message:
Quote:
"QODBCDriver::disconnect: Unable to disconnect datasource" Error: " [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionClose (closesocket()). [Microsoft][ODBC SQL Server Driver][DBNETLIB]" "QODBCDriver::cleanup: Unable to free connection handle" Error: " [Microsoft][ODBC Driver Manager] Function sequence error" "QODBCDriver::cleanup: Unable to free environment handle" Error: "[Microsoft][ODBC Driver Manager] Function sequence error "
However, if I call QSqlDatabase::remove() on each database name that I had created throughout the lifetime of the application, the program terminates fine and I don't see the message. Any ideas as to why I need to close each connection manually to prevent this error?
Re: QSqlDatabase Connection Close on Destruction
Same problem. can anyone help?
Same problem. can anyone help?
Added after 5 minutes:
This is my code:
Code:
int main(int argc, char *argv[]) {
QSettings& settings = *pSettings;
QString connectionTemplate
= "Driver={SQL Server};Server=%1;Database=%2;Uid=%3;Pwd=%4;";
QString server
= settings.
value("DBProductsServer").
toString();
QString database
= settings.
value("DBProductsDatabase").
toString();
QString user
= settings.
value("DBProductsUser").
toString();
QString pass
= settings.
value("DBProductsPass").
toString();
QString connectionString
= connectionTemplate
.arg(server)
.arg(database)
.arg(user)
.arg(pass);
db.setDatabaseName(connectionString);
if (db.open() ) {
std::cout << "DB Verbindung vorhanden" << std::endl;
while (query.next()) {
std::cout << query.value(0).toString().toStdString() << std::endl;
}
} else {
std::cout << error.databaseText().toStdString() << std::endl; ;
std::cout << error.driverText().toStdString() << std::endl; ;
std::cout << "Konnte keine DB Verbindung aufbauen" << std::endl;
}
return 0;
}
After execution I see the following error messages:
Code:
"QODBCDriver::disconnect: Unable to disconnect datasource" Error: " [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionClose (closesocket()). [Microsoft][ODBC SQL Server Driver][DBNETLIB]"
"QODBCDriver::cleanup: Unable to free connection handle" Error: " [Microsoft][ODBC Driver Manager] Fehler in der Funktionsreihenfolge"
"QODBCDriver::cleanup: Unable to free environment handle" Error: "[Microsoft][ODBC Driver Manager] Fehler in der Funktionsreihenfolge "