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. QSqlDatabase: How to close socket connection after network is unplug
Forum Updated to NodeBB v4.3 + New Features

QSqlDatabase: How to close socket connection after network is unplug

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 936 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
    uralbash
    wrote on 24 Nov 2017, 12:14 last edited by uralbash
    #1

    When I unplug Ethernet cable and then try to execute any QSqlQuery or call db.close(), db.commit(), etc.. These calls block the thread, until I plug cable back, it can be very long time. Also db.isOpen() everything is true. How do I force a break db connection if I know that the network connection was lost?

    I test it with FireBird.

    J 1 Reply Last reply 24 Nov 2017, 15:01
    0
    • U uralbash
      24 Nov 2017, 12:14

      When I unplug Ethernet cable and then try to execute any QSqlQuery or call db.close(), db.commit(), etc.. These calls block the thread, until I plug cable back, it can be very long time. Also db.isOpen() everything is true. How do I force a break db connection if I know that the network connection was lost?

      I test it with FireBird.

      J Offline
      J Offline
      JonB
      wrote on 24 Nov 2017, 15:01 last edited by
      #2

      @uralbash
      I don't think you can, TCP doesn't break connections when you unplug cables. You have to put timeouts in. AFAIK anyway.

      1 Reply Last reply
      0
      • U Offline
        U Offline
        uralbash
        wrote on 24 Nov 2017, 15:28 last edited by uralbash
        #3

        I do not need a timeout. I already know that the connection is broken. The question is how do I break the connection in QSqlDatabase object? Because db.close() block the thread and query.exec() block thread too and not close TCP connection just freezed.

        J 1 Reply Last reply 24 Nov 2017, 16:09
        0
        • U uralbash
          24 Nov 2017, 15:28

          I do not need a timeout. I already know that the connection is broken. The question is how do I break the connection in QSqlDatabase object? Because db.close() block the thread and query.exec() block thread too and not close TCP connection just freezed.

          J Offline
          J Offline
          JonB
          wrote on 24 Nov 2017, 16:09 last edited by
          #4

          @uralbash
          You may know the connection is broken, but TCP does not. So far as I know, it works by trying stuff and abandoning after a timeout. I don't know if you can do anything to avert that behaviour.

          1 Reply Last reply
          0

          1/4

          24 Nov 2017, 12:14

          • 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