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. Is it not possible to open M.S. access file?
QtWS25 Last Chance

Is it not possible to open M.S. access file?

Scheduled Pinned Locked Moved Solved General and Desktop
27 Posts 7 Posters 8.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
    rockon209
    wrote on 10 May 2017, 14:04 last edited by
    #4

    @mrjj
    I am using following code
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setDatabaseName("DRIVER={Microsoft Access Driver(*.accdb)};FIL={MS Access};DBQ=C:.........\Database1.accdb");

    if(db.open())
    qDebug() << "oK";
    else
    qDebug() << db.lastError();

    and i am getting the following error
    QSqlError("0", "QODBC3: Unable to connect", "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified")

    @koahnig
    I saved my file on my desktop, i think thats the most easy path and the above code is the simplest i guess.

    1 Reply Last reply
    0
    • H Online
      H Online
      hskoglund
      wrote on 10 May 2017, 14:15 last edited by
      #5

      Hi, try using an absolute filepath in the DBQ clause, for example:
      ;DBQ=c:\\myfolder\\Database1.accdb

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rockon209
        wrote on 10 May 2017, 14:22 last edited by
        #6

        @hskoglund
        i tried absolute filepath also but i am getting the same error

        1 Reply Last reply
        0
        • H Online
          H Online
          hskoglund
          wrote on 10 May 2017, 14:25 last edited by
          #7

          I see. Did you use double backslashes?

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rockon209
            wrote on 10 May 2017, 14:42 last edited by
            #8

            @hskoglund
            yes i tried with double backslashes and also with forward slashes. but same error

            1 Reply Last reply
            0
            • H Online
              H Online
              hskoglund
              wrote on 10 May 2017, 14:57 last edited by
              #9

              Hmm, create a folder called MyFolder on your C: , copy your Database1.accdb file into it and try:

              db.setDatabaseName("Driver=Microsoft Access Driver (*.mdb, *.accdb); DBQ=C:\\MyFolder\\Database1.accdb;";
              1 Reply Last reply
              2
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 10 May 2017, 16:43 last edited by
                #10

                Also, did you VERIFY that odbc is available and working ?
                https://www.isunshare.com/windows-10/5-ways-to-open-odbc-data-source-administrator-in-windows-10.html

                This might not be related to Qt at all.

                If you never worked with ODBC before, please study a bit
                http://www.dummies.com/programming/sql/how-to-use-odbc-to-access-sql-data/

                1 Reply Last reply
                2
                • R Offline
                  R Offline
                  rockon209
                  wrote on 11 May 2017, 06:24 last edited by
                  #11

                  @hskoglund

                  I tried what you suggested but getting the same error.

                  @mrjj

                  Yes the odbc is available and wroking.
                  and i just access the the file locally not via any server my file is in the same computer where i am writing the code

                  1 Reply Last reply
                  0
                  • H Online
                    H Online
                    hskoglund
                    wrote on 11 May 2017, 06:50 last edited by
                    #12

                    Hi, I googled a bit and found this thread

                    So if you do not have Microsoft Office installed you need to download the driver for MS Access .accdb files

                    A 1 Reply Last reply 11 May 2017, 07:23
                    2
                    • H hskoglund
                      11 May 2017, 06:50

                      Hi, I googled a bit and found this thread

                      So if you do not have Microsoft Office installed you need to download the driver for MS Access .accdb files

                      A Offline
                      A Offline
                      Andy314
                      wrote on 11 May 2017, 07:23 last edited by Andy314 5 Nov 2017, 07:28
                      #13

                      Indeed you must install the Access ODBC driver. The driver is independent from installed Office !
                      (Be aware Windows like to kill this driver after windows-update. So you must reinstall it sometimes.)

                      Then you must look in the ODBC tool from windows to find out the correct driver name. This is the correct for me (is not the same as you use):
                      "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};"

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        rockon209
                        wrote on 11 May 2017, 07:24 last edited by
                        #14

                        @hskoglund

                        i already tried downloaded and intalled the drivers, even though i have M.S Office installed on my computer. But getting the same error.

                        A 1 Reply Last reply 11 May 2017, 07:29
                        0
                        • R rockon209
                          11 May 2017, 07:24

                          @hskoglund

                          i already tried downloaded and intalled the drivers, even though i have M.S Office installed on my computer. But getting the same error.

                          A Offline
                          A Offline
                          Andy314
                          wrote on 11 May 2017, 07:29 last edited by
                          #15

                          Hi @rockon209
                          which Qt Version do you use?

                          1 Reply Last reply
                          0
                          • R Offline
                            R Offline
                            rockon209
                            wrote on 11 May 2017, 07:31 last edited by
                            #16

                            @Andy314
                            I am using Qt 5.7.0

                            A 1 Reply Last reply 11 May 2017, 07:38
                            0
                            • R rockon209
                              11 May 2017, 07:31

                              @Andy314
                              I am using Qt 5.7.0

                              A Offline
                              A Offline
                              Andy314
                              wrote on 11 May 2017, 07:38 last edited by Andy314 5 Nov 2017, 07:53
                              #17

                              Hi @rockon209
                              the QtCompany had the idea to do not distribute the binarys for the ODBC driver anymore. That was in Version 5.5 and 5.6 I think. I initiated a discussion about it. The result was that the driver should be integrated again. I dont know if this is in 5.7 really the case.

                              Look if you have in the path like C:\Qt2\5.6\msvc2015\plugins\sqldrivers
                              the qsqlodbc files.

                              1 Reply Last reply
                              0
                              • R Offline
                                R Offline
                                rockon209
                                wrote on 11 May 2017, 08:06 last edited by
                                #18

                                @Andy314

                                yes the file is present in the path.

                                A 1 Reply Last reply 11 May 2017, 08:14
                                0
                                • R rockon209
                                  11 May 2017, 08:06

                                  @Andy314

                                  yes the file is present in the path.

                                  A Offline
                                  A Offline
                                  Andy314
                                  wrote on 11 May 2017, 08:14 last edited by
                                  #19

                                  Hello @rockon209,
                                  oh I am happy :-)

                                  Now your Problem:
                                  It must work ! I use it since 1 year.

                                  We must find the error systhematic.
                                  First you should try a connection via the windows Windows-ODBC tool.
                                  I there is something wrong we must not look on Qt.

                                  1 Reply Last reply
                                  0
                                  • R Offline
                                    R Offline
                                    rockon209
                                    wrote on 11 May 2017, 08:19 last edited by
                                    #20

                                    @Andy314
                                    How to do that bcoz i new to this database access. I dont know how it works. Could you help me?

                                    A D 2 Replies Last reply 11 May 2017, 08:26
                                    0
                                    • R rockon209
                                      11 May 2017, 08:19

                                      @Andy314
                                      How to do that bcoz i new to this database access. I dont know how it works. Could you help me?

                                      A Offline
                                      A Offline
                                      Andy314
                                      wrote on 11 May 2017, 08:26 last edited by
                                      #21

                                      Hi @rockon209

                                      Search in Windows for "ODBC".
                                      Open the Program, dont know the english name. Something like "ODBC-Datasource 32-bit"
                                      Tabpage Drivers: Is there a entry like Microsoft Access Driver (*.mdb, *.accdb) ?

                                      more later...

                                      1 Reply Last reply
                                      0
                                      • R rockon209
                                        11 May 2017, 08:19

                                        @Andy314
                                        How to do that bcoz i new to this database access. I dont know how it works. Could you help me?

                                        D Offline
                                        D Offline
                                        Devopia53
                                        wrote on 11 May 2017, 08:30 last edited by Devopia53 5 Nov 2017, 11:30
                                        #22

                                        @rockon209

                                        Hi.

                                        Perhaps, you have a very minor problem.
                                        Compare the connection strings below.

                                        db.setDatabaseName("Driver={Microsoft Access Driver(*.mdb, *.accdb)}; DBQ=C:/MyFolder/Database1.accdb;"); // It's not OK!
                                        
                                        db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=C:/MyFolder/Database1.accdb;"); // It's OK!
                                        

                                        The ODBC driver is installed by default on Windows.

                                        A 1 Reply Last reply 11 May 2017, 08:37
                                        1
                                        • R Offline
                                          R Offline
                                          rockon209
                                          wrote on 11 May 2017, 08:36 last edited by
                                          #23

                                          @Andy314

                                          Yes entry is there in the Drivers Tab

                                          @Devopia53
                                          i tried it doest work same error again

                                          1 Reply Last reply
                                          0

                                          13/27

                                          11 May 2017, 07:23

                                          • Login

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