Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qsqldatabase can't connect to ms access database file
QtWS25 Last Chance

Qsqldatabase can't connect to ms access database file

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hadi
    wrote on last edited by
    #1

    hi
    i have a ms access file ...my file name is mydb.mdb and i use win7 64x and Qt 5.1 msvc 2012.
    now i want to load my db file and access to it's saved information.i put my db file in my hard disk C drive.
    my code is:

    @#pro file
    QT +=sql
    @

    MainWindow.cpp
    @
    QSqlDatabase mydb = QSqlDatabase::addDatabase("QODBC","mybasedb");
    qDebug()<<mydb.isValid()<<endl;//true
    mydb.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=C:\mydb.mdb");
    mydb.setConnectOptions("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");//force ODBC3.x behavior
    mydb.setHostName("localhost");
    mydb.setDatabaseName("mydb");
    mydb.setUserName("");
    mydb.setPassword("");
    bool opened=mydb.open();
    if(opened)
    QMessageBox::information(this,"Yeah","It's Perfect!");
    else
    {
    QMessageBox::information(this,"Oh",mydb.lastError().text());
    qDebug()<<mydb.lastError().text()<<endl;
    }
    @
    now i am trying to connect and open my db file but it can't open db file.
    how can i solve it???

    the error message is:

    bq. [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect;

    also can i load db file as bytearray or file object and then use it by QSqlDatabase?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved