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. Connection problem with an access file under Linux
Servers for Qt installer are currently down

Connection problem with an access file under Linux

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 6.6k Views 1 Watching
  • 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 Offline
    B Offline
    Bruschetta
    wrote on 17 Jul 2017, 07:34 last edited by
    #1

    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
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 17 Jul 2017, 07:55 last edited by
      #2

      @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 17 Jul 2017, 08:30
      0
      • M mrjj
        17 Jul 2017, 07:55

        @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 Offline
        B Offline
        Bruschetta
        wrote on 17 Jul 2017, 08:30 last edited by
        #3

        @mrjj
        Yes mbdTools is installed :(

        M 1 Reply Last reply 17 Jul 2017, 08:49
        0
        • B Bruschetta
          17 Jul 2017, 08:30

          @mrjj
          Yes mbdTools is installed :(

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 17 Jul 2017, 08:49 last edited by
          #4

          @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
          1
          • H Offline
            H Offline
            hskoglund
            wrote on 17 Jul 2017, 09:15 last edited by
            #5

            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
            2

            1/5

            17 Jul 2017, 07:34

            • Login

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