Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

auto reconnect to sql-database on connection loss



  • Hey guys,

    I have an application which is connected 24/7 to a MS-SQL database.
    If for some reason the connection is gone (i.e. server-restart) the client is woring anymore.
    Is there a global method to detect a lost connection and to restart it?

    I don't want to handle every execute statement individually.

    THX
    mts


  • Lifetime Qt Champion

    Hi,

    You should add which driver you are using to connect to that database as well as OS and Qt version.



  • I'm using the odbc-driver for linux (FreeTDS).
    QT 5.12



  • Hi, I had more or less the same problem, and instead of trying to keep the connection alive to the server, I resorted to a polling approach, i.e. say every 5 minutes, I'd close all active connections, close the database, open the database again and reestablish the queries (this depends of course how often you can accept loss of contact, for example a heartbeat-monitor in a hospital, in this case 5 minutes is not acceptable).


Log in to reply