Results 1 to 4 of 4

Thread: connection is not open

  1. #1
    Join Date
    Nov 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default connection is not open

    Hello, first I'm sorry for my english.

    So I try to connect to database trought QT4, but it doesn't work. Program is compiled, and I can run it, but the connection is not open. Do you know where is the problem?

    Code:

    Qt Code:
    1. #include <QtSql>
    2. #include <iostream>
    3. #include <QApplication>
    4. #include <QSqlDatabase>
    5.  
    6. int main(int argc, char *argv[]){
    7. QCoreApplication a(argc, argv);
    8. // server_name, db_name, user_name and password isn't real because of privacy
    9. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    10. db.setHostName("server_address");
    11. db.setDatabaseName("db_name");
    12. db.setUserName("user_name");
    13. db.setPassword("password");
    14. bool ok = db.open();
    15. if(ok){
    16. std::cout << "Connect...";
    17. }else{
    18. std::cout << "Not connect!"
    19. }
    20. return 0;
    21. }
    To copy to clipboard, switch view to plain text mode 

    When I run the programm I get: Not connect!
    Can anyone help me please?
    Last edited by jpn; 2nd December 2008 at 18:41. Reason: missing [code] tags

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: connection is not open

    * try printing the error message: QSqlDatabase::lastError()* also, check your console for errors: could the db driver plugin be found/loaded?

    HTH

  3. #3
    Join Date
    Nov 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: connection is not open

    thx, now it says: [unixODBC][Driver Manager]Data source name not found, and no default driver specified QODBC3: Unable to connect

    Do anyone know what cas I do?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: connection is not open

    You have to configure an ODBC connection.

    http://www.unixodbc.org/doc/

Similar Threads

  1. SQL connection closure problem.
    By cbarmpar in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2008, 08:42
  2. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 10:22
  3. Error signal connection between 2 classes
    By mattia in forum Newbie
    Replies: 6
    Last Post: 31st October 2007, 09:36
  4. again Open Cascade + Qt 4.2.2 but detailed...
    By Shuchi Agrawal in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2007, 06:50
  5. How do I keep the client connection open ?
    By probine in forum Newbie
    Replies: 2
    Last Post: 25th March 2006, 19:06

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.