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. unable to open MS-Access DB on QT Application
Forum Updated to NodeBB v4.3 + New Features

unable to open MS-Access DB on QT Application

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 1.6k 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.
  • M Offline
    M Offline
    mustafa
    wrote on last edited by
    #1

    i have a simple program in qt and what is this program do is to open\read a microsoft access datebase (.mdb or .accdb) and display the db tables.
    however my problem is that i cant even open the db at the first place
    i have db located in the c drive (C:\Qt_Project\Database1.accdb)
    in the (.pro) file i have included

    QT       += core gui sql
    

    included libraries are:

    #include <QSqlDatabase>
    #include <QDebug>
    #include <QSqlError>
    

    my code is:

    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC","AccessDB");
    db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=C://Qt_Project//Database1.accdb");
    if(db.open())
      qDebug() << "oK";
    else
      qDebug() << db.lastError().text();
    

    and finally my output is

     "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"
    

    i've goggled the web about this problem i'm facing and maybe "not sure" it's because of the registry because i usually use a cleaner to clean my pc which is cleaning registry also

    when i use the code

    bool ok = QSqlDatabase::isDriverAvailable("QODBC");
    

    it retures

    true
    

    that means there is no problems with the driver

    please help , thanks u

    Andy314A 1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      Hi, double forward slashes I think confuses Windows, try backward slashes instead:

      db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=C:\\Qt_Project\\Database1.accdb");
      
      1 Reply Last reply
      4
      • M Offline
        M Offline
        mustafa
        wrote on last edited by mustafa
        #3

        hello @hskoglund i did what you say and this was the output

        QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
        "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"
        
        JonBJ 1 Reply Last reply
        0
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #4

          Hmm, try simplifying by skipping the FILxx stuff::

          db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=C:\\Qt_Project\\Database1.accdb");
          

          Also, check that you have MS-Access installed on your computer and that you can open C:\Qt_Project\Database1.accdb from MS-Access.

          1 Reply Last reply
          2
          • M mustafa

            i have a simple program in qt and what is this program do is to open\read a microsoft access datebase (.mdb or .accdb) and display the db tables.
            however my problem is that i cant even open the db at the first place
            i have db located in the c drive (C:\Qt_Project\Database1.accdb)
            in the (.pro) file i have included

            QT       += core gui sql
            

            included libraries are:

            #include <QSqlDatabase>
            #include <QDebug>
            #include <QSqlError>
            

            my code is:

            QSqlDatabase db = QSqlDatabase::addDatabase("QODBC","AccessDB");
            db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=C://Qt_Project//Database1.accdb");
            if(db.open())
              qDebug() << "oK";
            else
              qDebug() << db.lastError().text();
            

            and finally my output is

             "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"
            

            i've goggled the web about this problem i'm facing and maybe "not sure" it's because of the registry because i usually use a cleaner to clean my pc which is cleaning registry also

            when i use the code

            bool ok = QSqlDatabase::isDriverAvailable("QODBC");
            

            it retures

            true
            

            that means there is no problems with the driver

            please help , thanks u

            Andy314A Offline
            Andy314A Offline
            Andy314
            wrote on last edited by
            #5

            @mustafa
            Please check this:

            bool ok=QSqlDatabase::isDriverAvailable("QODBC");
                if(!ok)
                {
                    ErrorMsg="No ODBC driver available!";
                    return 1;
                }
            
            JonBJ 1 Reply Last reply
            1
            • Andy314A Andy314

              @mustafa
              Please check this:

              bool ok=QSqlDatabase::isDriverAvailable("QODBC");
                  if(!ok)
                  {
                      ErrorMsg="No ODBC driver available!";
                      return 1;
                  }
              
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Andy314

              @mustafa wrote in the first post:

              when i use the code
              bool ok = QSqlDatabase::isDriverAvailable("QODBC");

              it retures
              true

              that means there is no problems with the driver

              1 Reply Last reply
              0
              • M mustafa

                hello @hskoglund i did what you say and this was the output

                QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
                "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"
                
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @Mustafa
                Apart from trying without the FIL= as @hskoglund has said, is it possible these days you have a 64- vs 32-bit issue with your drivers & Qt & your app? The sort of thing discussed in https://stackoverflow.com/a/25428598/489865 ?

                Alternatively, have you read the same question from a year ago and resolution at https://forum.qt.io/topic/81321/qtsql-data-source-name-not-found/4 ?

                Just a couple of thoughts, no point asking me further about this!

                1 Reply Last reply
                1
                • E Offline
                  E Offline
                  edwards142
                  Banned
                  wrote on last edited by
                  #8
                  This post is deleted!
                  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