Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Database is Open and is Valid but Server has gone away...

    General and Desktop
    3
    4
    358
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • U
      U7Development last edited by

      Hi !

      After some time of idle, the connection to database seems to be lost, lastError() returns "Server has gone away..." ..

      I thought i could control this by checking if isOpen() is false, if so, then i could try to re-connect to DB.. but isOpen() returns true even if the DB's server has gone away...

      The only becoming thing to my mind i can try is to detect the string error and check it, if it is "Server has gone away..." i reconnect to DB, but i'm pretty sure there must to be another way to check this..

      Any ideas?
      Thanks in advance.

      JonB Pablo J. Rogina 2 Replies Last reply Reply Quote 0
      • JonB
        JonB @U7Development last edited by JonB

        @U7Development said in Database is Open and is Valid but Server has gone away...:

        Server has gone away

        See the answer at https://stackoverflow.com/a/15059387/489865. It's from 2013, but that way may be just as valid now, since there doesn't seem to be anything better. There is an unaddressed bug report https://bugreports.qt.io/browse/QTBUG-223. There is also the MYSQL_OPT_RECONNECT (db.setConnectOptions("MYSQL_OPT_RECONNECT=1");) option if you are MySQL. You can also Google for qt database Server has gone away.

        U 1 Reply Last reply Reply Quote 2
        • U
          U7Development @JonB last edited by

          @JonB

          I'm using MariaDB (MySQL) and did not know about that string.. i will try it.
          MYSQL_OPT_RECONNECT (db.setConnectOptions("MYSQL_OPT_RECONNECT=1");)

          Thanks.

          1 Reply Last reply Reply Quote 0
          • Pablo J. Rogina
            Pablo J. Rogina @U7Development last edited by

            @U7Development said in Database is Open and is Valid but Server has gone away...:

            try is to detect the string error and check it,

            In addition to @JonB suggestion to use the reconnection setting, instead of checking the string you could check the error number (less error prone...) see this post

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply Reply Quote 2
            • First post
              Last post