PDA

View Full Version : error with QSqlQuery



mmm286
25th May 2010, 08:44
Hi,

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




db.setHostName("xx.xx.xx.xx");

db.setDatabaseName("prueba");
db.setUserName("xxxxxxx");
db.setPassword("yyyyyy");

if (!db.open())
{
QMessageBox::information(this, "Application name","not connected");
QMessageBox::information(this,"",db.lastError().text());
}

QSqlQuery query;

// bool r=db.open();
if( db.open() ) {
query = QSqlQuery("select * from USERSGROUPS");
//query.exec();
bool prueba = query.exec();
qDebug() << query.lastError().text();
QMessageBox::information(this,"",query.lastError().text());


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!

tbscope
25th May 2010, 09:20
Try setting the version number first before doing anything else



db.setConnectOptions("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");

mmm286
25th May 2010, 09:36
Try setting the version number first before doing anything else



db.setConnectOptions("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");


Many thanks but I have the same Error.
Any help?

tbscope
25th May 2010, 09:43
You did set that before you do db.open() ?

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

mmm286
25th May 2010, 09:57
Yes.
I put:


QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
qDebug() << "ODBC driver valid?" << db.isValid();
db.setConnectOptions("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");
db.setHostName("xx.xx.xx.xx");

db.setDatabaseName("prueba");


db.setUserName("xxxxxx");
db.setPassword("yyyyyyy");
....................



and nothing

ChrisW67
26th May 2010, 00:27
Hi,

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



query = QSqlQuery("select * from USERSGROUPS");


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?