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:


    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");
    if (!
    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?

  • Lifetime Qt Champion

    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