Results 1 to 10 of 10

Thread: ODBC function sequence error

  1. #1
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default ODBC function sequence error

    Hi guys

    My Code is something like this

    Qt Code:
    1. static bool DBConnection ::createODBC_Connection()
    2. {
    3. m_db = QSqlDatabase::addDatabase("QODBC");
    4.  
    5. m_db.setDatabaseName( "Test_DataSourceName" ); //DSN created in ControlPanel=> Administrative Tools ODBC Connection => System DSN =>..ADD
    6.  
    7. m_db.setConnectOptions ("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");
    8. if (! m_db.open())
    9. {
    10. return false;
    11. }
    12. return true;
    13. }
    To copy to clipboard, switch view to plain text mode 

    Now am using this code in main.cpp like this

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4.  
    5. if( ! DBConnection::createODBC_Connection() )
    6. {
    7. QMessageBox::information( 0 ,"" , DBConnection::getDBErrorInfo() );
    8. return 1;
    9. }
    10.  
    11. MainWindow w;
    12. w.show();
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 


    For testing this code i have created class MainWindow and put the code like this
    in the constructor itself
    Qt Code:
    1. #include <QSqlQuery>
    2. #include <QMessageBox>
    3. #include <QSqlError>
    4.  
    5. MainWindow::MainWindow(QWidget *parent)
    6. : QMainWindow(parent), ui(new Ui::MainWindowClass)
    7. {
    8. ui->setupUi(this);
    9. //TEST_BEGIN
    10. QSqlQuery query("SELECT name FROM employee where emp_id = 7");
    11. if( query.exec() )
    12. {
    13. if( query.next() ) //while (query.next())
    14. {
    15. QString empName = query.value(0).toString();
    16. this->setToolTip( empName );
    17. //QMessageBox::information( this ,"" ,empName );
    18. }
    19. }
    20. else
    21. {
    22. QMessageBox::information( this ," In Mainwindow::Mainwindow()" ,
    23. query.lastError().databaseText() +"\n" // Here i am getting ODBC //error "Function sequence error"
    24. // statement cann't be executed
    25.  
    26. + query.lastError().driverText() +"\n"
    27. + query.lastError().text() );
    28. }
    29. //TEST_END
    30.  
    31. }
    To copy to clipboard, switch view to plain text mode 

    When i am running my application i am getting following error ...
    [ODBC Driver Manager] "Function sequence error"
    [ODBC Driver Manager] can not execute statement
    [ODBC Driver Manager] "Function sequence error" QODBC3 : unable to execute statement


    MY Operating System = Windows XP
    IDE = QtCreator Beta ( comes with qt library )
    Database = Mysql
    ODBC Driver = Mysql ODBC 3.51 Driver ( i can see it in Control panel )

    Please correct me if am doing something wrong.

    thanks in advance

  2. #2
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: ODBC function sequence error

    Please help me with some tips to solve this ODBC error ....i got stuck with this issue..

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ODBC function sequence error

    Hi,

    Can you insert debug points and take a look on wich instructions get you this errors?
    Maybe then we can think on where is the problem.
    Òscar Llarch i Galán

  4. #4
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: ODBC function sequence error

    Quote Originally Posted by ^NyAw^ View Post
    Hi,

    Can you insert debug points and take a look on wich instructions get you this errors?
    Maybe then we can think on where is the problem.

    Thanks for your kind reponse.

    Actually i am getting this error in query.exec() as specified below...
    Qt Code:
    1. if( query.exec() )
    2. {
    3. if( query.next() ) //while (query.next())
    4. {
    5. QString empName = query.value(0).toString();
    6. this->setToolTip( empName );
    7. //QMessageBox::information( this ,"" ,empName );
    8. }
    9. }
    10. else // Control comes here inside this else block and i am able to see the query.lastError() ===> " [ODBC DRIVER] Function sequence error "
    11. {
    12. QMessageBox::information( this ," In Mainwindow::Mainwindow()" ,
    13. query.lastError().databaseText() +"\n"
    14. + query.lastError().driverText() +"\n"
    15. + query.lastError().text() );
    16. }
    To copy to clipboard, switch view to plain text mode 


    please tell me how can i resolve this ...

  5. #5
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ODBC function sequence error

    Hi,

    Maybe ODBC driver is case sensitive? I'm just thinking what is the problem, don't relly know what produces it.
    Try changing "where" to "WHERE" in your query.

    Also try removing this line:
    Qt Code:
    1. m_db.setConnectOptions ("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");
    To copy to clipboard, switch view to plain text mode 

    I can't find "SQL_ATTR_ODBC_VERSION" on "setConnectionOptions" doc.
    Òscar Llarch i Galán

  6. #6
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: ODBC function sequence error

    can someone help me ....
    am i doing something wrong in my code ( in above mention code snippt )...?

  7. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ODBC function sequence error

    try to connect to your database using Qt's example located on QTDIR/demos/sqlbrowser.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  8. #8
    Join Date
    Aug 2012
    Posts
    1
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ODBC function sequence error

    Quote Originally Posted by joseph View Post
    can someone help me ....
    am i doing something wrong in my code ( in above mention code snippt )...?
    I struggled with this for a bit and found out how to fix it. Change your code to:

    QSqlQuery query(QSqlDatabase::database());
    if( query.exec("SELECT name FROM employee where emp_id = 7") )

    It works, don't ask me why.

  9. #9
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ODBC function sequence error

    Have you got 64 bit windows?

  10. #10
    Join Date
    Mar 2012
    Location
    Bulgaria
    Posts
    5
    Thanks
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: ODBC function sequence error

    The documentation for the QSqlQuery constructor says "If query is not an empty string, it will be executed.", which means that when you call exec() you are executing it twice.

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43
  3. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  4. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 02:49
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.