Connection problem with an access file under Linux



  • 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!


  • Qt Champions 2016

    @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



  • @mrjj
    Yes mbdTools is installed :(


  • Qt Champions 2016

    @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



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.