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

[solved]guys what's wrong with my code? microsoft access database



  • Ok am trying to access a microsoft access database I've checked if the driver is available and yes QODBC is available I checked with the isDriverAvailable() code anyways here's my source code am looking forward to your advice:

    @
    QSqlDatabase DB = QSqlDatabase::addDatabase("QODBC");
    DB.setDatabaseName("Driver = {Microsoft Access Driver(.mdb,.accdb)}DSN='';DBQ=C:/Users/sweshi/Desktop/project.accdb");

    if(DB.open())
    {
    ui->label_6->setText("connected");
    }
    else
    {
    ui->label_6->setText("not connected");
    }
    @

    [andreyc EDIT]: added @ around code



  • small suggestion not sure if it will make a difference when using Qt but, I think the driver string is {Microsoft Access Driver (*.mdb, *.accdb)}.



  • Ok thanks for your contribution..still not working though..is there anything else I can add?





  • Hi I opened an Access .mdb file in Qt before, like this:
    @
    QSqlDatabase DB = QSqlDatabase::addDatabase("QODBC");
    DB.setDatabaseName("Driver={Microsoft Access Driver (*.mdb)}; Dbq=C:/Temp/Test.mdb;");@

    So maybe if you try to change your .setDatabaseName:
    @
    DB.setDatabaseName("Driver={Microsoft Access Driver (.mdb,.accdb)}; Dbq=C:/Users/sweshi/Desktop/project.accdb");
    @



  • There is also the issue of 32 bit and 64 bit access odbc drivers and on windows... you need to make sure you have the correct combination.



  • DB.lastError reports nothing thanks...@hskoglund I've tried that look at the application output: QSqlDatabase: QOBDC driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7. .@kenchan my windows 7 is 64bit but qt and ms access are both 32bit



  • I have a feeling it might be a problem with your ODBC driver settings on windows but can't be sure though

    Are you aware of the issue discussed here http://support.microsoft.com/kb/942976



  • Thanks bro its working thanks to that link



  • Glad I could be of help. It was not a Qt thing after all :-)


Log in to reply