Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Database is Open and is Valid but Server has gone away...
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 692 Views 1 Watching
  • 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 Offline
    U Offline
    U7Development
    wrote on 15 Oct 2020, 17:22 last edited by
    #1

    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.

    J P 2 Replies Last reply 15 Oct 2020, 17:51
    0
    • U U7Development
      15 Oct 2020, 17:22

      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.

      J Offline
      J Offline
      JonB
      wrote on 15 Oct 2020, 17:51 last edited by JonB
      #2

      @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 15 Oct 2020, 18:22
      2
      • J JonB
        15 Oct 2020, 17:51

        @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 Offline
        U Offline
        U7Development
        wrote on 15 Oct 2020, 18:22 last edited by
        #3

        @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
        0
        • U U7Development
          15 Oct 2020, 17:22

          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.

          P Offline
          P Offline
          Pablo J. Rogina
          wrote on 15 Oct 2020, 22:05 last edited by
          #4

          @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
          2

          1/4

          15 Oct 2020, 17:22

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved