Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Connection problem with an access file under Linux

    General and Desktop
    3
    5
    5773
    Loading More Posts
    • 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
      Bruschetta last edited by

      Hello to all.

      The problem I would like to address concerns the reading of a DB within an Access file under a Linux operating system.

      I have already followed this guide (http://doc.qt.io/qt-5/sql-driver.html) and installed unixODBC drivers.

      I’ll show you the code i’m using to connect to the DB:

        QSqlDatabase mydb;
          void connectionClose()
          {
              mydb.close();
              mydb.removeDatabase(QSqlDatabase::defaultConnection);
          }
      
       bool connectionOpen(){
                  mydb = QSqlDatabase::database("Contact");
                 if (mydb.isOpen()) {
                     return true;
                 }else{
                     static QString path = PATH;
                     path = QDir::toNativeSeparators(path);
                     mydb = QSqlDatabase::addDatabase("QODBC", "Contact");
      
                     QString params="Driver={Microsoft Access Driver (*.mdb,*.accdb)};FIL={Access};DBQ="+ path;
      
                     qDebug() <<"path --> " + params;
                     mydb.setDatabaseName(params);
      
                     if (!mydb.open())
                     {
                         qDebug() << "Error: connection with database fail";
                         qDebug() << mydb.lastError().text();
                         return false;
                     }
                     else
                     {
                         qDebug() << "Database: connection ok";
                         return true;
                     }
                     return true;
                 }
             }
      
      

      The error that my application launches when trying to access DB data is:

      "path --> Driver={Microsoft Access Driver (*.mdb,*.accdb)};FIL={Access};DBQ=/home/rusty/QTProjects/build-Beta-Desktop_Qt_5_9_1_GCC_64bit-Release/ContactEvo.mdb"
      
      Error: connection with database fail
      "[unixODBC][Driver Manager]Can't open lib 'Microsoft Access Driver (*.mdb,*.accdb)' : file not found QODBC3: Unable to connect"
      
      QSqlDatabasePrivate::database: unable to open database: "[unixODBC][Driver Manager]Can't open lib 'Microsoft Access Driver (*.mdb,*.accdb)' : file not found QODBC3: Unable to connect"
      

      Can you see where the mistake might be? The application under Windows runs without any kind of problem..

      thank you for your time!

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        @Bruschetta said in Connection problem with an access file under Linux:

        unixODBC

        Hi
        Did you also install drivers for mdb ?
        https://github.com/brianb/mdbtools

        B 1 Reply Last reply Reply Quote 0
        • B
          Bruschetta @mrjj last edited by

          @mrjj
          Yes mbdTools is installed :(

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @Bruschetta last edited by

            @Bruschetta

            Im not sure you still must do this
            but did you also tell odbc about the driver ?

            /etc/odbcinst.ini:

            [MDBTools]
            Description = MDBTools Driver
            Driver = libmdbodbc.so.1
            Setup = libmdbodbc.so.1
            FileUsage = 1
            UsageCount = 1

            https://github.com/brianb/mdbtools/issues/116

            http://qgqlochekone.blogspot.dk/2017/06/odbc-devuan-and-debian-complete-how-to.html#install_and_prepare_mdbtools_odbc

            1 Reply Last reply Reply Quote 1
            • hskoglund
              hskoglund last edited by

              Hi also you can look at this thread (it's also about reading Access .mdb files under Linux)

              Two conclusions from that thread: you'll need a patched version of qsql_odbc.cpp, otherwise you'll get these kind of errors once the odbcxxx.ini files are fixed:
              Error at Line : syntax error near 'test'
              syntax error near 'test'
              Got no result for 'select 'test'' command
              QODBCDriver::checkHasSQLFetchScroll: Warning - Driver doesn't support scrollable result sets, use forward only mode for queries

              and also, even with the patched version qsql_odbc.cpp, the mdbtools driver seems to be read-only with very limited functionality :-(

              P.S. isql is your friend

              1 Reply Last reply Reply Quote 2
              • First post
                Last post