Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to create a new xx.mdb(MS access file) file using qt?



  • When I use sqlite, if I wanna create a new xx.db file, I usually use this function:

    ...
    QSqlDatabase::setDatabaseName("test.db");
    ...

    If the test.db is NOT exist, qt will create it automatically. But when I turn to MS access and still use this function:

    ...
    QSqlDatabase accessdb = QSqlDatabase::addDatabase("QODBC", "test");
    QString dsn = QString("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=mytest.mdb");
    accessdb.setDatabaseName(dsn);
    if (!accessdb.open())
    {
    qDebug() << accessdb.lastError().text();
    }
    ...

    I can only be told “[Microsoft][ODBC Microsoft Access driver] file not found '(unknown)'"
    which might means qt only find it without creating it automatically.

    How to create a new xx.mdb file using qt?


  • Qt Champions 2019

    It looks like your Qt installation does not contain the driver for MS Access



  • @jsulm But I'm sure I installed it formly...


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    I haven't used ODBC actively but IIRC, you have to do some setup in order to access MSAccess databases through it (not unlike what you would have to do for a MySQL database) so basically you have to provide the .mdb file.


Log in to reply