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. [SOLVED] Qt 4.7.3, ODBC driver, error when connecting to db

[SOLVED] Qt 4.7.3, ODBC driver, error when connecting to db

Scheduled Pinned Locked Moved General and Desktop
15 Posts 3 Posters 15.5k 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.
  • G Offline
    G Offline
    garfungiloops
    wrote on last edited by
    #1

    I have the following problem with the ODBC driver.

    I have 2 versions of QT on the same PC.

    1. "2010.02.1" used with MSVS2005 (x32)
    2. "4.7.3" used with MSVS2010 (x64)

    I need to connect to DBASE "*.dbf" database. (The odbc driver is compiled as a plugin in both cases)
    The connection string is:

    @ db = QSqlDatabase::addDatabase("QODBC");
    QString connect_str("DRIVER={Microsoft dBASE Driver (*.dbf)};DBQ=");
    connect_str.append(_db_path);
    db.setDatabaseName(connect_str);
    if (!db.open()) {
    QSqlError err = db.lastError ();
    QString s_err("The database reported an error: ");
    s_err.append(err.databaseText());
    throw std::logic_error(s_err.toAscii().data());
    }@

    In case 1. everything works perfectly
    In case 2. I'm getting the error: "Datasource name not found and no default driver specified"

    I debugged a little, the Qt function which fails is:
    qsql_odbc.cpp, line 1885
    @r = SQLDriverConnect(...)@

    Anyone knows the reason?

    Eddy : added code tags, please use @ tags for your code

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Do you have system ODBC drivers for 64bit architecture?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • G Offline
        G Offline
        garfungiloops
        wrote on last edited by
        #3

        What do you mean by system driver?
        I have compiled a Qt ODBC driver for 64 bit yes.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          You always need the drivers for your database and some generic system drivers for ODBC. Qt uses those to wrap the calls into its own database abstraction layer. If only one of those is missing, the driver cannot be loaded. So make sure you have 64bit versions of the system ODBC and of the driver for your specific database.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • G Offline
            G Offline
            garfungiloops
            wrote on last edited by
            #5

            Ok. It seems I understood what you mean.
            I'm using win 7 x64 for both cases.
            I'm sure that I have a correct Qt database driver (Otherwise Qt generates another error smth like "QODBC not loaded"). Now we are coming to system driver. I guess you mean OS driver, something like "odbcad32.exe" right?
            My assumption is that this it is loading automatically, since so far I had no problems with that.
            But may be you are right, does that means that Windows is loading a 32 bit driver (on 64 bit system) by default and I need 64 bit one? Do you know anything how to switch them?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              As long as your application is 64bit, all loaded libs must be 64bit too. As your application works as 32bit version, it's very likely that you do not have the 64bit drivers installed or in the right path. Fortunately I didn't have to deal with ODBC so far, so unfortunately for you I cannot be of big help here :-)

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • G Offline
                G Offline
                garfungiloops
                wrote on last edited by
                #7

                Yes, my all libs all are 64 bit (for case 2), but it seems that the ODBC driver comes with the Office (and it is 32 bits in my case ). It is possible to install "MS AccessDatabaseEngine X64", but then office is not working correctly any more. (according to the forum here (sorry in German) http://www.windows-7-forum.net/windows-7-software/15054-32-bit-64-bit-odbc-problem.html )

                But anyway, thanks for pointing me to the right direction, now I know at least where to search :-)

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  You're welcome! If you find a solution, please add to the thread here - some users stepping into that trap later will surely be thankful :-)

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    garfungiloops
                    wrote on last edited by
                    #9

                    The solution was really easy:
                    The connection string must be exactly this

                    @
                    "DRIVER={Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)};DBQ=".
                    @

                    Without those stupid "*.ndx, *.mdx" it doesn't work on x64 but works perfectly on x86.
                    (Database is *.dbf)
                    I "love" Microsoft :-)

                    [EDIT: code formatting for the string, Volker]

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      confused
                      wrote on last edited by
                      #10

                      how did you define _db_path? Ive been getting this same problem, along with many others, but I attempted to use this but didnt know what exactly _db_path should be to make it work

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        garfungiloops
                        wrote on last edited by
                        #11

                        "_db_path" is just a path to your DB directory, i.e. the location of your DBF files. Note, that you don't need to include a "DBF" filename here, only the path to the directory. The DBF can be accessed then like following:
                        "SELECT * FROM YOURFILENAME.DBF"

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          confused
                          wrote on last edited by
                          #12

                          So I could put the SELECT statement in place of _db_path?

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            garfungiloops
                            wrote on last edited by
                            #13

                            No. "_db_path" is appended to the connection string (in the above example).
                            I mean that you should include only the folder name into the "_db_path".
                            The filename is used as a table name in the sql query. "SELECT ..." is the SQL query of course.

                            1 Reply Last reply
                            0
                            • C Offline
                              C Offline
                              confused
                              wrote on last edited by
                              #14

                              Oh Ok. Sorry I'm new to Qt and SQL and. So I would replace _db_path with "C:\Users..." pointing to the folder the .dbf is in? Also can you tell me how to create the .dbf? The only examples I've seen use SQLlight and .dat files so I can't figure out how to make the .dbf or just access a database I made directly in SQL. Would I just add the disired filename here
                              @QString connect_str("DRIVER={Microsoft dBASE Driver (*.dbf)};DBQ=");@

                              like this
                              @QString connect_str("DRIVER={Microsoft dBASE Driver (*.dbf)};DBQ=filename");@

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                garfungiloops
                                wrote on last edited by
                                #15

                                [quote author="confused" date="1342446698"]So I would replace _db_path with "C:\Users..." pointing to the folder the .dbf is in? [/quote]

                                Yes

                                [quote author="confused" date="1342446698"]
                                Also can you tell me how to create the .dbf?
                                [/quote]

                                You should execute a query "CREATE TABLE YOURFILE.DBF"

                                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