Results 1 to 2 of 2

Thread: QSqlDatabase Connection Close on Destruction

  1. #1
    Join Date
    Jan 2010
    Posts
    14
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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:

    "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?

  2. #2
    Join Date
    Sep 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlDatabase Connection Close on Destruction

    Same problem. can anyone help?

    Same problem. can anyone help?


    Added after 5 minutes:


    This is my code:

    Qt Code:
    1. int main(int argc, char *argv[]) {
    2. QSettings* pSettings = new QSettings(QDir::currentPath() + "/" + CONFIG_FILE, QSettings::IniFormat);
    3. QSettings& settings = *pSettings;
    4.  
    5. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    6. QString connectionTemplate = "Driver={SQL Server};Server=%1;Database=%2;Uid=%3;Pwd=%4;";
    7.  
    8. QString server = settings.value("DBProductsServer").toString();
    9. QString database = settings.value("DBProductsDatabase").toString();
    10. QString user = settings.value("DBProductsUser").toString();
    11. QString pass = settings.value("DBProductsPass").toString();
    12.  
    13. QString connectionString = connectionTemplate
    14. .arg(server)
    15. .arg(database)
    16. .arg(user)
    17. .arg(pass);
    18.  
    19. db.setDatabaseName(connectionString);
    20.  
    21. if (db.open() ) {
    22. std::cout << "DB Verbindung vorhanden" << std::endl;
    23. QSqlQuery query("SELECT * FROM dbo.BOM");
    24.  
    25. while (query.next()) {
    26. std::cout << query.value(0).toString().toStdString() << std::endl;
    27. }
    28. } else {
    29. QSqlError error = db.lastError();
    30. std::cout << error.databaseText().toStdString() << std::endl; ;
    31. std::cout << error.driverText().toStdString() << std::endl; ;
    32.  
    33. std::cout << "Konnte keine DB Verbindung aufbauen" << std::endl;
    34. }
    35.  
    36. return 0;
    37. }
    To copy to clipboard, switch view to plain text mode 


    After execution I see the following error messages:
    Qt Code:
    1. "QODBCDriver::disconnect: Unable to disconnect datasource" Error: " [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionClose (closesocket()). [Microsoft][ODBC SQL Server Driver][DBNETLIB]"
    2. "QODBCDriver::cleanup: Unable to free connection handle" Error: " [Microsoft][ODBC Driver Manager] Fehler in der Funktionsreihenfolge"
    3. "QODBCDriver::cleanup: Unable to free environment handle" Error: "[Microsoft][ODBC Driver Manager] Fehler in der Funktionsreihenfolge "
    To copy to clipboard, switch view to plain text mode 
    Last edited by m0n0g0n; 1st September 2011 at 15:32.

Similar Threads

  1. QSqlDatabase PSQL connection options
    By leknarf in forum Qt Programming
    Replies: 0
    Last Post: 17th March 2010, 16:06
  2. Replies: 1
    Last Post: 16th March 2010, 15:46
  3. QSqlDatabase::close() sigsev exception
    By Raccoon29 in forum Qt Programming
    Replies: 1
    Last Post: 21st December 2009, 08:54
  4. What happens after closing and before destruction?
    By Raccoon29 in forum Qt Programming
    Replies: 45
    Last Post: 20th May 2008, 09:33
  5. Replies: 3
    Last Post: 22nd June 2006, 16:27

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.