Results 1 to 11 of 11

Thread: Qt Microsoft Access Connecion Problem on Windows

  1. #1
    Join Date
    Apr 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Qt Microsoft Access Connecion Problem on Windows

    Hello.
    I've been working on a project I used QSqlite on Linux and it worked perfectly. But when I
    decided to build my project on Windows QSqlite didn't work. So I decided
    to connect to Access I used the connection string on Qt docs "DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb"
    but when I run my project Qt gives me this error "QSqlQuery::exec: database not open
    "QODBCResult::exec: No statement handle available" Error: "[Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'." "
    Can you please help me!? It's so important!
    Thanks in advance!
    Note: I tried compiling ODBC driver.

  2. #2
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Microsoft Access Connecion Problem on Windows

    Hi,
    This works for me :

    Qt Code:
    1. *dbDci = QSqlDatabase::addDatabase("QODBC");
    2. dbDci->setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MSAccess};DBQ=dci.mdb");
    3. dbDci->open();
    To copy to clipboard, switch view to plain text mode 

    'dci.mdb' is the name of my MS Access file.

    Also, in the .pro file of your project, you have to put QT += sql.
    Are the odbc DLL's present in your plugins directory ?

    Best regards,
    Marc

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Qt Microsoft Access Connecion Problem on Windows

    Quote Originally Posted by Furkan View Post
    But when I
    decided to build my project on Windows QSqlite didn't work.
    If you're still interested in using SQLite on Windows too, can you give us the error you got?

  4. #4
    Join Date
    Apr 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Qt Microsoft Access Connecion Problem on Windows

    It doesn't give any errors but when I debug my code, at while(readPassword.next()) step nothing happens. I'm pretty sure that the database contains passwords and usernames. There is nothing wrong with the code because it works on Linux. And in this directory "C:\Qt\2010.05\qt\plugins\sqldrivers" qsqlite4.dll, qsqlited4.dll, qsqlodbc4.dll, qsqlodbcd4.dll files exist.

  5. #5
    Join Date
    Apr 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Qt Microsoft Access Connecion Problem on Windows

    OK guys! I've solved the problem. After installing the drivers it worked. I thought I installed them but apparently I didn't. Thank you all for your support.

  6. #6
    Join Date
    Apr 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Qt Microsoft Access Connecion Problem on Windows

    There is a problem again. It worked once and startted giving errors. Here is the code. Please help me I've been trying to solve it ever since it gave me the problem. Please guys!
    QSqlDatabase database = QSqlDatabase::addDatabase("QODBC");
    database.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MSAccess};DBQ=Database.mdb");
    database.open();
    QMessageBox::information(this, "1212321123123213123123", database.lastError().text());
    QSqlQuery readPassword("SELECT * FROM password WHERE username=:username");
    readPassword.bindValue(":username", ui->lineEdit_2->text());
    readPassword.exec();
    if(ui->lineEdit->text().isEmpty() || ui->lineEdit_2->text().isEmpty())
    {
    QMessageBox::information(this,"Hata", QString::fromUtf8("Fill in the blanks!"));
    database.close();
    this->show();
    }
    else
    {
    bool yes = false;
    while(readPassword.next())
    {
    QString string = readPassword.value(0).toString();
    QString string1 = readPassword.value(1).toString();
    if(string == ui->lineEdit->text() && string1 == ui->lineEdit_2->text())
    {
    database.close();
    notTakip.show();
    notTakip.setPermitedUsername(ui->lineEdit_2->text(), readPassword.value(2).toString().toInt());
    notTakip.prepareNotTakip();
    yes = true;
    this->close();
    break;
    }
    }
    if(yes == false)
    {
    QMessageBox::information(this, "Error", readPassword.lastError().text());
    QMessageBox::information(this,"Error", QString::fromUtf8("Wrong username or password!"));
    ui->lineEdit->clear();
    database.close();
    this->show();
    }
    }
    The error when I run it with Qt Creator: {Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'. QODBC3: Unable to connect.
    When I run the executable the error is: {Microsoft][ODBC Driver Manager] Function sequence error QODBC3: Unable to execute statement.

  7. #7
    Join Date
    Apr 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Qt Microsoft Access Connecion Problem on Windows

    Also QSqlDatabase::isDriverAvailable("QODBC") returns true!

  8. #8
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: Qt Microsoft Access Connecion Problem on Windows

    Quote Originally Posted by Furkan View Post
    The error when I run it with Qt Creator: {Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'. QODBC3: Unable to connect.
    Make sure that your database file is in the same directory with your executable.

    Quote Originally Posted by Furkan View Post
    When I run the executable the error is: {Microsoft][ODBC Driver Manager] Function sequence error QODBC3: Unable to execute statement.
    Modify your codes from
    Qt Code:
    1. QSqlQuery readPassword("SELECT * FROM password WHERE username=:username");
    2. readPassword.bindValue(":username", ui->lineEdit_2->text());
    3. readPassword.exec();
    To copy to clipboard, switch view to plain text mode 

    to
    Qt Code:
    1. QSqlQuery readPassword;
    2. readPassword.prepare("SELECT * FROM password WHERE username=:username");
    3. readPassword.bindValue(":username", ui->lineEdit_2->text());
    4. readPassword.exec();
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Apr 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Qt Microsoft Access Connecion Problem on Windows

    Thank you so much! It worked. But Can you tell me the reason why use prepare?
    And when I try to run the executable it works nice but on another computer with necessary Qt dlls (Qt Framwork isn't installed) it doesn't work. Gives this error "Database driver not loaded".
    Do you know how to fix it?

  10. #10
    Join Date
    Apr 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Qt Microsoft Access Connecion Problem on Windows

    Thank you all. I've solved the problem.
    From this link

  11. #11
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: Qt Microsoft Access Connecion Problem on Windows

    Quote Originally Posted by Furkan View Post
    Can you tell me the reason why use prepare?
    Because you use prepared statement. Take a look at QSqlQuery::prepare(const QString &).

Similar Threads

  1. Replies: 1
    Last Post: 20th September 2010, 16:49
  2. Looking Native on Windows, saying similar to Microsoft Office
    By henry_shanghai in forum General Discussion
    Replies: 4
    Last Post: 30th May 2010, 14:35
  3. Access to the Recycle Bin (Windows)
    By Nedec in forum Newbie
    Replies: 1
    Last Post: 22nd December 2009, 20:54
  4. access between windows
    By DarsVaeda in forum Qt Programming
    Replies: 1
    Last Post: 8th October 2008, 09:56
  5. how to connect to a microsoft access database?
    By mismael85 in forum Qt Programming
    Replies: 3
    Last Post: 7th March 2008, 09:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.