Results 1 to 6 of 6

Thread: error with QSqlQuery

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default error with QSqlQuery

    Hi,

    I'm trying to do a select of a database like this:

    Qt Code:
    1. db.setHostName("xx.xx.xx.xx");
    2.  
    3. db.setDatabaseName("prueba");
    4. db.setUserName("xxxxxxx");
    5. db.setPassword("yyyyyy");
    6.  
    7. if (!db.open())
    8. {
    9. QMessageBox::information(this, "Application name","not connected");
    10. QMessageBox::information(this,"",db.lastError().text());
    11. }
    12.  
    13. QSqlQuery query;
    14.  
    15. // bool r=db.open();
    16. if( db.open() ) {
    17. query = QSqlQuery("select * from USERSGROUPS");
    18. //query.exec();
    19. bool prueba = query.exec();
    20. qDebug() << query.lastError().text();
    21. QMessageBox::information(this,"",query.lastError().text());
    To copy to clipboard, switch view to plain text mode 

    it gives me: [Microsoft][ODBC controllers admin] Function sequence error QODBC3: Unable to execute statement

    Could you help me please?
    Many thanks and sorry for my english!

  2. #2
    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: error with QSqlQuery

    Try setting the version number first before doing anything else

    Qt Code:
    1. db.setConnectOptions("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: error with QSqlQuery

    Quote Originally Posted by tbscope View Post
    Try setting the version number first before doing anything else

    Qt Code:
    1. db.setConnectOptions("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");
    To copy to clipboard, switch view to plain text mode 
    Many thanks but I have the same Error.
    Any help?

  4. #4
    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: error with QSqlQuery

    You did set that before you do db.open() ?

    If so, try making your db synchronous (see ODBC documentation).

  5. #5
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Unhappy Re: error with QSqlQuery

    Yes.
    I put:
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    2. qDebug() << "ODBC driver valid?" << db.isValid();
    3. db.setConnectOptions("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");
    4. db.setHostName("xx.xx.xx.xx");
    5.  
    6. db.setDatabaseName("prueba");
    7.  
    8.  
    9. db.setUserName("xxxxxx");
    10. db.setPassword("yyyyyyy");
    11. ....................
    To copy to clipboard, switch view to plain text mode 

    and nothing

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: error with QSqlQuery

    Quote Originally Posted by mmm286 View Post
    Hi,

    I'm trying to do a select of a database like this:

    Qt Code:
    1. query = QSqlQuery("select * from USERSGROUPS");
    To copy to clipboard, switch view to plain text mode 

    it gives me: [Microsoft][ODBC controllers admin] Function sequence error QODBC3: Unable to execute statement
    You don't say exactly which line is generating this message, so I am assuming that it is the exec() call and not the two attempts to open() the database. Is "USERSGROUPS" a table or view in the underlying database? Is the underlying database case sensitive with respect to table name? Could double opening the connection be causing an issue here?

Similar Threads

  1. about QSqlQuery ,how can i get columns
    By tsuibin in forum Newbie
    Replies: 3
    Last Post: 28th March 2010, 19:29
  2. QSqlquery
    By codeman in forum Qt Programming
    Replies: 10
    Last Post: 4th June 2009, 12:57
  3. what is going on a QSqlQuery?
    By mismael85 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2008, 13:35
  4. QSqlQuery error
    By skuda in forum Qt Programming
    Replies: 2
    Last Post: 2nd November 2007, 08:43
  5. QSqlQuery problem
    By dragon in forum Newbie
    Replies: 5
    Last Post: 22nd December 2006, 17:32

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
  •  
Qt is a trademark of The Qt Company.