Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. Qt Contribution
  4. how to set the connect blocking time when use QSqlDatabase::open()?
Forum Updated to NodeBB v4.3 + New Features

how to set the connect blocking time when use QSqlDatabase::open()?

Scheduled Pinned Locked Moved Unsolved Qt Contribution
9 Posts 2 Posters 2.1k 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.
  • boom stackB Offline
    boom stackB Offline
    boom stack
    wrote on last edited by
    #1

    now i use QSqlDatabase::open() to connect the sql sever.
    After reading Qt help,i use QSqlDatabase::setConnectOptions() to set the blocking time.

    QSqlDatabase db;
    /*......*/
    db.setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=3");
    

    when i input the wrong ip,like196.168.0.999,the code work,db.open() will blocking 3s .
    but when i input a legal but unconnectable ip like 196.168.0.1, the code doesn‘t work,db.open() will blocking about 50s .

    How to solve this problem?how to set the blocking time?

    JonBJ 1 Reply Last reply
    0
    • boom stackB boom stack

      now i use QSqlDatabase::open() to connect the sql sever.
      After reading Qt help,i use QSqlDatabase::setConnectOptions() to set the blocking time.

      QSqlDatabase db;
      /*......*/
      db.setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=3");
      

      when i input the wrong ip,like196.168.0.999,the code work,db.open() will blocking 3s .
      but when i input a legal but unconnectable ip like 196.168.0.1, the code doesn‘t work,db.open() will blocking about 50s .

      How to solve this problem?how to set the blocking time?

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

      @boom-stack
      Do you mean it only blocks 50s when you have that line, or would it still block 50s without that line?

      You don't say anything about what your database is. In any case, that option will be passed on directly from Qt, Qt does nothing about it, so you should search the web for solutions relevant to your database.

      1 Reply Last reply
      0
      • boom stackB Offline
        boom stackB Offline
        boom stack
        wrote on last edited by
        #3

        i use QSqlDatabase to connect the sql server.
        With that line or without that line,when i input a legal but unconnectable ip like 196.168.0.1,they both will block 50s.

        JonBJ 1 Reply Last reply
        0
        • boom stackB boom stack

          i use QSqlDatabase to connect the sql server.
          With that line or without that line,when i input a legal but unconnectable ip like 196.168.0.1,they both will block 50s.

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

          @boom-stack said in how to set the connect blocking time when use QSqlDatabase::open()?:

          i use QSqlDatabase to connect the sql server.

          I know that. But that says nothing about what the SQL server is. It might be SQLite, MySQL, MariaDB, PostgreSQL, ... Whichever it is, that is who interprets the SQL_ATTR_LOGIN_TIMEOUT=3 --- I think it's actually the ODBC driver, so that may be what you have to Google to address your question.

          1 Reply Last reply
          0
          • boom stackB Offline
            boom stackB Offline
            boom stack
            wrote on last edited by
            #5

            yeah it's actually the ODBC driver,but i just don’t know how to set the connect blocking time by use QSqlDatabase::setConnectOptions().
            except this line

            db.setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=3");
            

            what should i set?
            ![alt text](ddf55b60-1044-4ec1-9211-3b1a58dfd3bf-image.png image url)

            JonBJ 1 Reply Last reply
            0
            • boom stackB boom stack

              yeah it's actually the ODBC driver,but i just don’t know how to set the connect blocking time by use QSqlDatabase::setConnectOptions().
              except this line

              db.setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=3");
              

              what should i set?
              ![alt text](ddf55b60-1044-4ec1-9211-3b1a58dfd3bf-image.png image url)

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

              @boom-stack
              I don't know either, that's why I said you'll want to Google!

              Purely at a guess, since you're saying it spends 50 seconds trying and failing to connect, did you investigate SQL_ATTR_CONNECTION_TIMEOUT?

              1 Reply Last reply
              0
              • boom stackB Offline
                boom stackB Offline
                boom stack
                wrote on last edited by
                #7

                yes i try,but it doesn't work
                hhhhokok,whatever thank you bro.

                JonBJ 1 Reply Last reply
                0
                • boom stackB boom stack

                  yes i try,but it doesn't work
                  hhhhokok,whatever thank you bro.

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

                  @boom-stack
                  Then I think you have a problem! I see e.g. https://stackoverflow.com/questions/2309684/connection-timeout-in-odbc saying you should do this via SQL_ATTR_CONNECTION_TIMEOUT, but then as per the last answer there https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2012/ms131709(v%3Dsql.110) states

                  The SQL Server Native Client ODBC driver ignores the setting of SQL_ATTR_CONNECTION_TIMEOUT.

                  So it may depend on on which client ODBC driver you use.....

                  I would do a lot of Googling :)

                  1 Reply Last reply
                  0
                  • boom stackB Offline
                    boom stackB Offline
                    boom stack
                    wrote on last edited by
                    #9

                    i did a lot google,but maybe i ignore something.
                    thank you bro!it help

                    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