Not able to open Microsoft Access file



  • Hello everyone i am using the following code to open the Microsoft Access file

    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setDatabaseName("DRIVER={Microsoft Access Driver(*.accdb)};FIL={MS Access};DBQ=C:\..\...\....\Database1.accdb");

    if(db.open())
    qDebug() << "oK";
    else
    qDebug() << db.lastError();

    and i am getting the following error
    QSqlError("0", "QODBC3: Unable to connect", "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified")
    please help- Thanks in advance


  • Moderators

    @rockon209 said in Not able to open Microsoft Access file:

    ODBC Driver Manager] Data source name not found and no default driver specified

    Sometimes Google is your best friend

    Considering the relative path you are using that link will probably give a hint (found with the Google search above)

    OK, just saw that your relative path might be a stripped down absolute path and trying to hide the details.
    Checkout the details there. The db has to be there where you expect it.
    Note: Single backslash are typically not a good idea in C/C++ and for absolute and relative file path, they are deadly. Use single forward slashes which are also supported by Windows and common on other OS.



  • @koahnig
    I tried with two back slashes and with forward slashes also but both gave me same error


Log in to reply
 

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