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. Can't properly detect QSqlDatabase disconnect
Forum Updated to NodeBB v4.3 + New Features

Can't properly detect QSqlDatabase disconnect

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 4.3k 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.
  • R Offline
    R Offline
    raulvc
    wrote on last edited by
    #1

    Hello everyone, I have an issue trying to do a few things if an unexpected connection loss occurs, that is, a database disconnection.

    My approach was using a method *isOpen()*on a QSqlDatabase object,
    which is apparently unreliable for this scenario (it keeps returning true even when db connection is lost)

    Can anyone direct me on how to do this detection?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      QSqlDatabase::isOpen() cannot possibly know if the intervening network is down permanently or if the remote server has shutdown/crashed because there is no mechanism by which it is told. When normal long network timeouts expire it may start to return false.

      Run a known good query. If the query fails, probably with QSqlError::ConnectionError or QSqlError::UnknownError, then the connection is not usable.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        raulvc
        wrote on last edited by
        #3

        unfortunately, query hangs until timeout (which is inconceivably high)

        is there a way to reduce query timeout?

        E 1 Reply Last reply
        0
        • R raulvc

          unfortunately, query hangs until timeout (which is inconceivably high)

          is there a way to reduce query timeout?

          E Offline
          E Offline
          EmoBemo
          wrote on last edited by
          #4

          @raulvc I tried calling transaction() and if the connection was timed out it return false in no time. This is how I know to close() the connection and open() it again. If transaction() returns true just call rollback(). I would like to see more opinions on that.

          1 Reply Last reply
          0

          • Login

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