PDA

View Full Version : ODBC function sequence error



joseph
17th February 2009, 07:48
Hi guys

My Code is something like this




static bool DBConnection ::createODBC_Connection()
{
m_db = QSqlDatabase::addDatabase("QODBC");

m_db.setDatabaseName( "Test_DataSourceName" ); //DSN created in ControlPanel=> Administrative Tools ODBC Connection => System DSN =>..ADD

m_db.setConnectOptions ("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");
if (! m_db.open())
{
return false;
}
return true;
}


Now am using this code in main.cpp like this



int main(int argc, char *argv[])
{
QApplication a(argc, argv);

if( ! DBConnection::createODBC_Connection() )
{
QMessageBox::information( 0 ,"" , DBConnection::getDBErrorInfo() );
return 1;
}

MainWindow w;
w.show();
return a.exec();
}





For testing this code i have created class MainWindow and put the code like this
in the constructor itself


#include <QSqlQuery>
#include <QMessageBox>
#include <QSqlError>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);
//TEST_BEGIN
QSqlQuery query("SELECT name FROM employee where emp_id = 7");
if( query.exec() )
{
if( query.next() ) //while (query.next())
{
QString empName = query.value(0).toString();
this->setToolTip( empName );
//QMessageBox::information( this ,"" ,empName );
}
}
else
{
QMessageBox::information( this ," In Mainwindow::Mainwindow()" ,
query.lastError().databaseText() +"\n" // Here i am getting ODBC //error "Function sequence error"
// statement cann't be executed

+ query.lastError().driverText() +"\n"
+ query.lastError().text() );
}
//TEST_END

}


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

joseph
17th February 2009, 10:41
Please help me with some tips to solve this ODBC error ....i got stuck with this issue.. :(

^NyAw^
17th February 2009, 11:28
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.

joseph
17th February 2009, 12:00
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...


if( query.exec() )
{
if( query.next() ) //while (query.next())
{
QString empName = query.value(0).toString();
this->setToolTip( empName );
//QMessageBox::information( this ,"" ,empName );
}
}
else // Control comes here inside this else block and i am able to see the query.lastError() ===> " [ODBC DRIVER] Function sequence error "
{
QMessageBox::information( this ," In Mainwindow::Mainwindow()" ,
query.lastError().databaseText() +"\n"
+ query.lastError().driverText() +"\n"
+ query.lastError().text() );
}



please tell me how can i resolve this ...:confused:

^NyAw^
17th February 2009, 12:19
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:


m_db.setConnectOptions ("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");


I can't find "SQL_ATTR_ODBC_VERSION" on "setConnectionOptions" doc.

joseph
19th February 2009, 08:07
can someone help me ....:(
am i doing something wrong in my code ( in above mention code snippt )...?:confused:

spirit
19th February 2009, 08:24
try to connect to your database using Qt's example located on QTDIR/demos/sqlbrowser.

mwaqqas
10th August 2012, 01:44
can someone help me ....:(
am i doing something wrong in my code ( in above mention code snippt )...?:confused:

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.

Viper666
12th August 2012, 11:17
Have you got 64 bit windows?

emobemo
7th November 2014, 12:32
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.