How long does an opened database connection remain open?



  • If I open a database connection, like so:
    @
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setHostName("localhost");
    db.setDatabaseName("mya.db");
    if (db.open()){....}@

    How long is this guaranteed to remain open and available for queries? Under what circumstances might it get closed?



  • Until you close() it, call removeDatabase(), or an exception situation like disk full occurs. If you are connected to a remote database (say MySQL or Oracle) then the connection may close as a result of the server closing the connection or because of network failures.

    BTW: Line 2 is unnecessary for Sqlite



  • That sounds pretty convenient. If I understand correctly, for a local database, I can expect that once I open it, the database is available from everywhere unless the program crashes or I manually close or remove it. That sounds pretty dependable.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.