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 ODBC and timeout
Forum Updated to NodeBB v4.3 + New Features

QSqlDatabase ODBC and timeout

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 1.8k Views 2 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.
  • M Offline
    M Offline
    Mwoua
    wrote on 15 Jul 2019, 17:52 last edited by Mwoua
    #1

    Hello,
    i'm trying to change the connect timeout of my OBDC sql.

        QSqlDatabase lSqlDatabase = QSqlDatabase::addDatabase( "QODBC", "databasename" );
        lSqlDatabase.setDatabaseName("DRIVER=SQL Server;SERVER=servername;DATABASE=databasename");
        lSqlDatabase.setConnectOptions( "SQL_ATTR_CONNECTION_TIMEOUT=2;SQL_ATTR_LOGIN_TIMEOUT=2" );
        auto a = lSqlDatabase.connectOptions();
    
        lSqlDatabase.open(); //Really slow
    

    The timeout doesnt change, and when I try to get the connect options, I get nothing. LastError returns nothing aswell.

    Any idea on how to actually change the timeout?

    S J 2 Replies Last reply 16 Jul 2019, 09:45
    0
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 15 Jul 2019, 20:19 last edited by
      #2

      have you tried using one of the many ODBC DSN connection testing utilities out there to verify that the DSN is valid in the first place? Also, google indicates that you can supply connection options as part of the DSN connection string.

      1 Reply Last reply
      0
      • M Mwoua
        15 Jul 2019, 17:52

        Hello,
        i'm trying to change the connect timeout of my OBDC sql.

            QSqlDatabase lSqlDatabase = QSqlDatabase::addDatabase( "QODBC", "databasename" );
            lSqlDatabase.setDatabaseName("DRIVER=SQL Server;SERVER=servername;DATABASE=databasename");
            lSqlDatabase.setConnectOptions( "SQL_ATTR_CONNECTION_TIMEOUT=2;SQL_ATTR_LOGIN_TIMEOUT=2" );
            auto a = lSqlDatabase.connectOptions();
        
            lSqlDatabase.open(); //Really slow
        

        The timeout doesnt change, and when I try to get the connect options, I get nothing. LastError returns nothing aswell.

        Any idea on how to actually change the timeout?

        S Offline
        S Offline
        sneubert
        wrote on 16 Jul 2019, 09:45 last edited by
        #3

        @Mwoua said in QSqlDatabase ODBC and timeout:

            QSqlDatabase lSqlDatabase = QSqlDatabase::addDatabase( "QODBC", "databasename" );
            lSqlDatabase.setDatabaseName(DRIVER=SQL Server;SERVER=servername;DATABASE=databasename);
            lSqlDatabase.setConnectOptions( "SQL_ATTR_CONNECTION_TIMEOUT=2;SQL_ATTR_LOGIN_TIMEOUT=2" );
            auto a = lSqlDatabase.connectOptions();
        
            lSqlDatabase.open(); //Really slow
        

        Is this a typo? Your connection string Driver attribute should look like: Driver={SQL Server}

        1 Reply Last reply
        1
        • M Mwoua
          15 Jul 2019, 17:52

          Hello,
          i'm trying to change the connect timeout of my OBDC sql.

              QSqlDatabase lSqlDatabase = QSqlDatabase::addDatabase( "QODBC", "databasename" );
              lSqlDatabase.setDatabaseName("DRIVER=SQL Server;SERVER=servername;DATABASE=databasename");
              lSqlDatabase.setConnectOptions( "SQL_ATTR_CONNECTION_TIMEOUT=2;SQL_ATTR_LOGIN_TIMEOUT=2" );
              auto a = lSqlDatabase.connectOptions();
          
              lSqlDatabase.open(); //Really slow
          

          The timeout doesnt change, and when I try to get the connect options, I get nothing. LastError returns nothing aswell.

          Any idea on how to actually change the timeout?

          J Offline
          J Offline
          JonB
          wrote on 16 Jul 2019, 10:05 last edited by JonB
          #4

          @Mwoua
          Further to @sneubert , could you explain how the line you have pasted from your code:

          lSqlDatabase.setDatabaseName(DRIVER=SQL Server;SERVER=servername;DATABASE=databasename);

          gets through your compiler, given that it's not valid in C++?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mwoua
            wrote on 22 Jul 2019, 14:54 last edited by Mwoua
            #5

            Sorry for the delay.

            @Kent-Dorfman It's valid, im trying to change the timeout when the user isnt connected to our VPN and has no access to the databse. When the user is on our network, it works correctly.
            I didnt find anything to set the timeout in the connection string, do you have an example?

            @JonB Its a variable in the code, I forgot to add the quote when i replaced it. First post edited

            @sneubert the setDatabaseName argument doesnt have any {} and it seems to work when the database is reachable

            EDIT: I found these two links
            https://docs.microsoft.com/en-us/sql/relational-databases/native-client-odbc-api/sqlsetconnectattr?view=sql-server-2017
            https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlsetconnectattr-function?view=sql-server-2017

            and the first one says that SQL_ATTR_CONNECTION_TIMEOUT is ignored. Maybe thats the problem

            1 Reply Last reply
            0

            1/5

            15 Jul 2019, 17:52

            • Login

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