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. connecting MS Access in Qt 5.15
QtWS25 Last Chance

connecting MS Access in Qt 5.15

Scheduled Pinned Locked Moved Unsolved General and Desktop
database driver
13 Posts 4 Posters 2.6k 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.
  • D dan1973
    9 Apr 2022, 10:25

    @JonB i tried reinstalling MS Office - MS Access 2007 also. after restarting the pc, still same problem. whether, you also face this problem?

    J Offline
    J Offline
    JonB
    wrote on 9 Apr 2022, 10:49 last edited by
    #4

    @dan1973
    Reinstalling Office is not the issue. I said you need to verify what ODBC connection string is needed/works external to your Qt program.

    No I don't face such a problem as I don't use Windows for programming. When I have in the past you have to get the ODBC connection string correct.

    D 1 Reply Last reply 9 Apr 2022, 11:08
    0
    • J JonB
      9 Apr 2022, 10:49

      @dan1973
      Reinstalling Office is not the issue. I said you need to verify what ODBC connection string is needed/works external to your Qt program.

      No I don't face such a problem as I don't use Windows for programming. When I have in the past you have to get the ODBC connection string correct.

      D Offline
      D Offline
      dan1973
      wrote on 9 Apr 2022, 11:08 last edited by
      #5

      @JonB
      Following is the output i get in excel when i run the prepared dqy file(see dqy file also below)
      Excel output:
      ExcelOutput.png

      dqy file:

      XLODBC
      1
      Driver={Microsoft Access Driver (*.mdb)};DSN='ms32';DBQ=C:\\LCA_MC.mdb;
      SELECT BusName FROM BusInfo
      

      I then used the Driver string in my code still the same problem.

          QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
          db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb)};DSN='ms32';DBQ=C:\\LCA_MC.mdb;");
      
          if(db.open())
            qDebug() << "oK";
          else
            qDebug() << db.lastError().text();
      
      
      J 1 Reply Last reply 9 Apr 2022, 11:22
      0
      • D dan1973
        9 Apr 2022, 11:08

        @JonB
        Following is the output i get in excel when i run the prepared dqy file(see dqy file also below)
        Excel output:
        ExcelOutput.png

        dqy file:

        XLODBC
        1
        Driver={Microsoft Access Driver (*.mdb)};DSN='ms32';DBQ=C:\\LCA_MC.mdb;
        SELECT BusName FROM BusInfo
        

        I then used the Driver string in my code still the same problem.

            QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
            db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb)};DSN='ms32';DBQ=C:\\LCA_MC.mdb;");
        
            if(db.open())
              qDebug() << "oK";
            else
              qDebug() << db.lastError().text();
        
        
        J Offline
        J Offline
        JonB
        wrote on 9 Apr 2022, 11:22 last edited by
        #6

        @dan1973
        I know nothing about this, but the examples at https://www.connectionstrings.com/access-2007/ do not pass any DSN=... argument. Do you need that, can it be removed?

        D C 2 Replies Last reply 9 Apr 2022, 11:28
        1
        • D Offline
          D Offline
          dan1973
          wrote on 9 Apr 2022, 11:27 last edited by
          #7

          i removed the "DSN='ms32'" string from Driver string. still the same error. But it executes the dqy file into excel output.

          1 Reply Last reply
          0
          • J JonB
            9 Apr 2022, 11:22

            @dan1973
            I know nothing about this, but the examples at https://www.connectionstrings.com/access-2007/ do not pass any DSN=... argument. Do you need that, can it be removed?

            D Offline
            D Offline
            dan1973
            wrote on 9 Apr 2022, 11:28 last edited by
            #8

            @JonB We normally connect the Database "LCA_MC.mdb" using DSN name (Data Source Name)

            J 1 Reply Last reply 9 Apr 2022, 11:33
            0
            • D dan1973
              9 Apr 2022, 11:28

              @JonB We normally connect the Database "LCA_MC.mdb" using DSN name (Data Source Name)

              J Offline
              J Offline
              JonB
              wrote on 9 Apr 2022, 11:33 last edited by JonB 4 Sept 2022, 11:34
              #9

              @dan1973
              There are loads of Google hits for "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified .

              I think you are supposed to go into ODBC Data Source Administrator (32-bit? 64-bit? I think it's important you configure whatever the right one is being used by your Qt program) and have a look through the tabs to see what is configured/available to you.

              So far as I can see the Qt ODBC driver is installed correctly and the error comes from the ODBC driver on the connection string.

              1 Reply Last reply
              0
              • J JonB
                9 Apr 2022, 11:22

                @dan1973
                I know nothing about this, but the examples at https://www.connectionstrings.com/access-2007/ do not pass any DSN=... argument. Do you need that, can it be removed?

                C Offline
                C Offline
                ChrisW67
                wrote on 10 Apr 2022, 07:43 last edited by
                #10

                @dan1973 Further to what @JonB noted, the examples on the Connection Strings site for an ODBC connection to Access are of the form:

                Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\mydatabase.accdb;...
                

                I expect if you open the ODBC admin tool this is exactly the name you will see on the system drivers tab.

                Notice that the driver name here includes two different file extensions and differs from yours:

                Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.accdb;...
                
                D 1 Reply Last reply 11 Apr 2022, 06:09
                0
                • C ChrisW67
                  10 Apr 2022, 07:43

                  @dan1973 Further to what @JonB noted, the examples on the Connection Strings site for an ODBC connection to Access are of the form:

                  Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\mydatabase.accdb;...
                  

                  I expect if you open the ODBC admin tool this is exactly the name you will see on the system drivers tab.

                  Notice that the driver name here includes two different file extensions and differs from yours:

                  Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.accdb;...
                  
                  D Offline
                  D Offline
                  dan1973
                  wrote on 11 Apr 2022, 06:09 last edited by
                  #11

                  @ChrisW67

                  I used the following codes:
                  1.

                      QString strDatabasePath = "C:/LCA_MC.mdb";
                      QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
                      QString strDbName = QString("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=%1").arg(strDatabasePath);
                      //db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=c:/ada.mdb");
                      db.setDatabaseName(strDbName);
                      bool ok = db.open();
                  
                      if(ok) qDebug() << "Success";
                      else qDebug() << db.lastError().text();
                  
                      QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
                      QString strDbName = QString("Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\\LCA_MC.mdb;Uid=;Pwd=;");
                      db.setDatabaseName(strDbName);
                      bool ok = db.open();
                  
                      if(ok) qDebug() << "Success";
                      else qDebug() << db.lastError().text();
                  

                  Still i get the same error:
                  "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"

                  I have a doubt: why QODBC3? since i am using QODBC.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mchinand
                    wrote on 11 Apr 2022, 13:01 last edited by mchinand 4 Nov 2022, 13:47
                    #12

                    Also, be aware that the Access ODBC connector is likely 32-bit so your application has to be 32-bit. It's been quite a while since I used the Access ODBC with Qt, but I remember trying to install a 64-bit version of the connector but that created other MS Office issues.

                    J 1 Reply Last reply 11 Apr 2022, 13:03
                    0
                    • M mchinand
                      11 Apr 2022, 13:01

                      Also, be aware that the Access ODBC connector is likely 32-bit so your application has to be 32-bit. It's been quite a while since I used the Access ODBC with Qt, but I remember trying to install a 64-bit version of the connector but that created other MS Office issues.

                      J Offline
                      J Offline
                      JonB
                      wrote on 11 Apr 2022, 13:03 last edited by
                      #13

                      @mchinand
                      I tried pointing this out to the OP earlier with

                      I think you are supposed to go into ODBC Data Source Administrator (32-bit? 64-bit? I think it's important you configure whatever the right one is being used by your Qt program) and have a look through the tabs to see what is configured/available to you.

                      but don't hear much back that s/he has tried.

                      1 Reply Last reply
                      1

                      13/13

                      11 Apr 2022, 13:03

                      • Login

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