Hi guys
My Code is something like this
static bool DBConnection ::createODBC_Connection()
{
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;
}
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;
}
To copy to clipboard, switch view to plain text mode
Now am using this code in main.cpp like this
int main(int argc, char *argv[])
{
if( ! DBConnection::createODBC_Connection() )
{
QMessageBox::information( 0 ,
"" , DBConnection
::getDBErrorInfo() );
return 1;
}
MainWindow w;
w.show();
return a.exec();
}
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();
}
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
#include <QSqlQuery>
#include <QMessageBox>
#include <QSqlError>
MainWindow
::MainWindow(QWidget *parent
){
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
}
#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
}
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
Bookmarks