Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. check if the sql connection is alive
Forum Updated to NodeBB v4.3 + New Features

check if the sql connection is alive

Scheduled Pinned Locked Moved Solved Qt for Python
7 Posts 3 Posters 2.9k Views
  • 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
    rhx9
    wrote on last edited by
    #1

    Hi,
    How can i check if the connection to the database is alive? after the connection is established the isOpen() will always return true even if the connection is dropped(i.e the database server is down or unreachable)
    so how can i check if the connection is really alive and can accept queries?

    regards

    JonBJ 1 Reply Last reply
    0
    • R rhx9

      Hi,
      How can i check if the connection to the database is alive? after the connection is established the isOpen() will always return true even if the connection is dropped(i.e the database server is down or unreachable)
      so how can i check if the connection is really alive and can accept queries?

      regards

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @rhx9 said in check if the sql connection is alive:

      so how can i check if the connection is really alive and can accept queries?

      Send it a query.

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

        First try:

        if(!db.open()){
                qDebug() << "SQL Database not Connected";
            }
            else {
                qDebug() << "SQL Database is Connected";
            }
        

        Than make your query and try:

        if(!query.isActive()){
                qWarning() << "ERROR: " << query.lastError().text();
            }
        
        1 Reply Last reply
        0
        • JonBJ JonB

          @rhx9 said in check if the sql connection is alive:

          so how can i check if the connection is really alive and can accept queries?

          Send it a query.

          R Offline
          R Offline
          rhx9
          wrote on last edited by
          #4

          @JonB said in check if the sql connection is alive:

          @rhx9 said in check if the sql connection is alive:

          so how can i check if the connection is really alive and can accept queries?

          Send it a query.

          That's what i eventually did, ( I sent this query SELECT 1 every 4 seconds to check if the database is alive)
          Thanks

          JonBJ 1 Reply Last reply
          0
          • R rhx9

            @JonB said in check if the sql connection is alive:

            @rhx9 said in check if the sql connection is alive:

            so how can i check if the connection is really alive and can accept queries?

            Send it a query.

            That's what i eventually did, ( I sent this query SELECT 1 every 4 seconds to check if the database is alive)
            Thanks

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @rhx9
            Yep, that's the only sure way to determine...

            I sent this query SELECT 1 every 4 seconds to check if the database is alive

            Umm, yes, but why? This keeps both your app and the database (e.g. if it's a SQL server) busy. You're not really supposed to do that. What is the point of this, you are just supposed to send the queries you actually want when you want them, I can't see what your regular query achieves?

            R 1 Reply Last reply
            0
            • JonBJ JonB

              @rhx9
              Yep, that's the only sure way to determine...

              I sent this query SELECT 1 every 4 seconds to check if the database is alive

              Umm, yes, but why? This keeps both your app and the database (e.g. if it's a SQL server) busy. You're not really supposed to do that. What is the point of this, you are just supposed to send the queries you actually want when you want them, I can't see what your regular query achieves?

              R Offline
              R Offline
              rhx9
              wrote on last edited by
              #6

              @JonB said in check if the sql connection is alive:

              @rhx9
              Yep, that's the only sure way to determine...

              I sent this query SELECT 1 every 4 seconds to check if the database is alive

              Umm, yes, but why? This keeps both your app and the database (e.g. if it's a SQL server) busy. You're not really supposed to do that. What is the point of this, you are just supposed to send the queries you actually want when you want them, I can't see what your regular query achieves?

              I do this to check if the sql connection is alive, if it is alive and can accept queries a signal will be emitted that will show an icon in the status bar that indicates the db connection is ok, if the connection is not ok an icon that shows the connection is not ok will be shown.

              Regards

              JonBJ 1 Reply Last reply
              0
              • R rhx9

                @JonB said in check if the sql connection is alive:

                @rhx9
                Yep, that's the only sure way to determine...

                I sent this query SELECT 1 every 4 seconds to check if the database is alive

                Umm, yes, but why? This keeps both your app and the database (e.g. if it's a SQL server) busy. You're not really supposed to do that. What is the point of this, you are just supposed to send the queries you actually want when you want them, I can't see what your regular query achieves?

                I do this to check if the sql connection is alive, if it is alive and can accept queries a signal will be emitted that will show an icon in the status bar that indicates the db connection is ok, if the connection is not ok an icon that shows the connection is not ok will be shown.

                Regards

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @rhx9
                Well like I said you're not really supposed to do that. For example, if this were on a mobile/laptop neither the client nor the server (if remote) machine will ever get to sleep/hibernate. Even on a desktop if I run up your program and walk away for two days it will still keep both ends busy. Your client is supposed to be (sort of) "stateless" like an HTTP connection, we don't (or shouldn't) have a web page constantly polling the server.

                Up to you.

                1 Reply Last reply
                2

                • Login

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