Is it not possible to open M.S. access file?

  • Hello everyone,
    Is it not possible to open M.S. Access file in Qt.
    I tried with SQLITE file and i can open it but not the M.S.Access file.
    Is there any special way to open Microsoft access file

  • Qt Champions 2016

    You must use ODBC to open a ms access file.

  • Moderators


    See also your other post and the documentation It is an example there.

    I would recommend trying with a small example and a less complicated name for the file path.

  • @mrjj
    I am using following code
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setDatabaseName("DRIVER={Microsoft Access Driver(*.accdb)};FIL={MS Access};DBQ=C:.........\Database1.accdb");

    qDebug() << "oK";
    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")

    I saved my file on my desktop, i think thats the most easy path and the above code is the simplest i guess.

  • Hi, try using an absolute filepath in the DBQ clause, for example:

  • @hskoglund
    i tried absolute filepath also but i am getting the same error

  • I see. Did you use double backslashes?

  • @hskoglund
    yes i tried with double backslashes and also with forward slashes. but same error

  • Hmm, create a folder called MyFolder on your C: , copy your Database1.accdb file into it and try:

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

  • Qt Champions 2016

    Also, did you VERIFY that odbc is available and working ?

    This might not be related to Qt at all.

    If you never worked with ODBC before, please study a bit

  • @hskoglund

    I tried what you suggested but getting the same error.


    Yes the odbc is available and wroking.
    and i just access the the file locally not via any server my file is in the same computer where i am writing the code

  • Hi, I googled a bit and found this thread

    So if you do not have Microsoft Office installed you need to download the driver for MS Access .accdb files

  • Indeed you must install the Access ODBC driver. The driver is independent from installed Office !
    (Be aware Windows like to kill this driver after windows-update. So you must reinstall it sometimes.)

    Then you must look in the ODBC tool from windows to find out the correct driver name. This is the correct for me (is not the same as you use):
    "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};"

  • @hskoglund

    i already tried downloaded and intalled the drivers, even though i have M.S Office installed on my computer. But getting the same error.

  • Hi @rockon209
    which Qt Version do you use?

  • @Andy314
    I am using Qt 5.7.0

  • Hi @rockon209
    the QtCompany had the idea to do not distribute the binarys for the ODBC driver anymore. That was in Version 5.5 and 5.6 I think. I initiated a discussion about it. The result was that the driver should be integrated again. I dont know if this is in 5.7 really the case.

    Look if you have in the path like C:\Qt2\5.6\msvc2015\plugins\sqldrivers
    the qsqlodbc files.

  • @Andy314

    yes the file is present in the path.

  • Hello @rockon209,
    oh I am happy :-)

    Now your Problem:
    It must work ! I use it since 1 year.

    We must find the error systhematic.
    First you should try a connection via the windows Windows-ODBC tool.
    I there is something wrong we must not look on Qt.

  • @Andy314
    How to do that bcoz i new to this database access. I dont know how it works. Could you help me?

  • Hi @rockon209

    Search in Windows for "ODBC".
    Open the Program, dont know the english name. Something like "ODBC-Datasource 32-bit"
    Tabpage Drivers: Is there a entry like Microsoft Access Driver (*.mdb, *.accdb) ?

    more later...

  • @rockon209


    Perhaps, you have a very minor problem.
    Compare the connection strings below.

    db.setDatabaseName("Driver={Microsoft Access Driver(*.mdb, *.accdb)}; DBQ=C:/MyFolder/Database1.accdb;"); // It's not OK!
    db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=C:/MyFolder/Database1.accdb;"); // It's OK!

    The ODBC driver is installed by default on Windows.

  • @Andy314

    Yes entry is there in the Drivers Tab

    i tried it doest work same error again

  • Jup, use exactly the name shown in the ODBC tool !!!!!

  • ok thank you very much guys it worked i was not using the proper syntax.
    Thank you very much.

  • Go in the ODBC tool to the File-DSN tab.

    Top right button like Add or Create new
    choose the Access odbc driver -> click >>
    as next set a filename -> click >>
    next windows choose a *.accdb file
    ready -> you have a DSN file which defines the connection.

    I thought the ODBC tool has a function to test this connection directly, but it has not. So a file.dsn testing program would be nice ....
    I found out a testing methode with Excel Data Tab->Extern Data -> Data connection Assistant -> ODBC DSN -> and choosed the pervious integrated dsn-file.

    Nevertheless you should use the content of this file as the connect string in Qt.
    only DRIVER and DBQ are important here.

    and you should check in Qt:
    bool ok=QSqlDatabase::isDriverAvailable("QODBC");
    ErrorMsg="No ODBC driver available!";
    return 1;

Log in to reply