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. Qt to open .mdb file, failed at IM002 QODBC: Unable to connect
Forum Updated to NodeBB v4.3 + New Features

Qt to open .mdb file, failed at IM002 QODBC: Unable to connect

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 451 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.
  • Q Offline
    Q Offline
    qGavin
    wrote on last edited by
    #1

    So I want to read the .mdb file with Qt, and I am stuck at IM002 QODBC: Unable to connect. Already posted on question StackOverflow but regarded as Duplicate. Already checked the bitness and driver name as in this question: Why am I getting "Data source name not found and no default driver specified" and how do I fix it? and still failed.

    Checking if the file exists, return true. Checking if the driver exists and is valid, return true. Create a dummy file with MS Access 64bit on same Laptop (since mykit is Qt 6.7 64bit to avoid 32bit vs 64bit difference) still creating that error.

    Here is my code snippet

    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    QString path = "F:\\SKJ Trial\\test data\\Dummy_64bit.mdb";
    QString str_comm = "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=";
    
    qDebug() << "Is Db valid: " + QVariant(db.isValid()).toString();
    qDebug() << "path: " + path;
    qDebug() << "Is file exist: " + QVariant(QFile(path).exists()).toString();
    
    str_comm += path;
    db.setDatabaseName(str_comm);
    qDebug() << "String command: " + str_comm;
    db.open();
    
    if(db.isOpen()){
        qDebug() << "Success";
    } else {
        qDebug() << "Failed";
        qDebug() << db.lastError().text();
    }
    

    and the console log is here:

    "Is Db valid: true"
    "path: F:\\SKJ Trial\\test data\\Dummy_64bit.mdb"
    "Is file exist: true"
    "String command: DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=F:\\SKJ Trial\\test data\\Dummy_64bit.mdb"
    Failed
    "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, IM002 QODBC: Unable to connect"
    

    Could anyone help me if I'm missing something?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      I can see nothing wrong with the advice in the Stack Overflow post you linked to.

      The other thing to be aware of is that you must be checking the 64-bit or 32-bit ODBC manager as appropriate for the bit-ness (word?) of your executable. Your 64-bit tool chain can make a 32-bit application. The drivers are separate and it is very easy to look at the wrong set. See this for example of ODBC confusion:
      863c576a-6627-4053-972b-24aae5ce42a3-image.png

      Other things to try:

      • Use a path that does not contain a space
      • Define a dedicated data source in ODBC manager and connect using that name
      Christian EhrlicherC 1 Reply Last reply
      0
      • C ChrisW67

        I can see nothing wrong with the advice in the Stack Overflow post you linked to.

        The other thing to be aware of is that you must be checking the 64-bit or 32-bit ODBC manager as appropriate for the bit-ness (word?) of your executable. Your 64-bit tool chain can make a 32-bit application. The drivers are separate and it is very easy to look at the wrong set. See this for example of ODBC confusion:
        863c576a-6627-4053-972b-24aae5ce42a3-image.png

        Other things to try:

        • Use a path that does not contain a space
        • Define a dedicated data source in ODBC manager and connect using that name
        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Also see https://forum.qt.io/topic/155973

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        Q 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          Also see https://forum.qt.io/topic/155973

          Q Offline
          Q Offline
          qGavin
          wrote on last edited by
          #4

          @Christian-Ehrlicher Thanks dude, after trying the same code with Qt 6.6.3 the connection works. So we just need to wait for a patch for this problem. Dang, I thought there was an error in my code or my setup.

          1 Reply Last reply
          0
          • Q qGavin has marked this topic as solved on
          • Christian EhrlicherC Christian Ehrlicher referenced this topic on

          • Login

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