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.
  • B Offline
    B Offline
    boom stack
    wrote on 14 Jan 2021, 03:17 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?

    J 1 Reply Last reply 14 Jan 2021, 07:44
    0
    • B boom stack
      14 Jan 2021, 03:17

      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?

      J Offline
      J Offline
      JonB
      wrote on 14 Jan 2021, 07:44 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
      • B Offline
        B Offline
        boom stack
        wrote on 14 Jan 2021, 08:24 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.

        J 1 Reply Last reply 14 Jan 2021, 08:55
        0
        • B boom stack
          14 Jan 2021, 08:24

          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.

          J Offline
          J Offline
          JonB
          wrote on 14 Jan 2021, 08:55 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
          • B Offline
            B Offline
            boom stack
            wrote on 14 Jan 2021, 09:07 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)

            J 1 Reply Last reply 14 Jan 2021, 09:09
            0
            • B boom stack
              14 Jan 2021, 09:07

              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)

              J Offline
              J Offline
              JonB
              wrote on 14 Jan 2021, 09:09 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
              • B Offline
                B Offline
                boom stack
                wrote on 14 Jan 2021, 09:17 last edited by
                #7

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

                J 1 Reply Last reply 14 Jan 2021, 09:27
                0
                • B boom stack
                  14 Jan 2021, 09:17

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

                  J Offline
                  J Offline
                  JonB
                  wrote on 14 Jan 2021, 09:27 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
                  • B Offline
                    B Offline
                    boom stack
                    wrote on 14 Jan 2021, 09:43 last edited by
                    #9

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

                    1 Reply Last reply
                    0

                    1/9

                    14 Jan 2021, 03:17

                    • Login

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