I have a problem executing SQL statements in my Qt program through an ODBC-Driver, the connection to the Database works fine and is not a problem.
Setup:
What is Acron:
Acron is a plant data acquisition & reports for process optimization system.
My problem:
When I send/execute SQL querys from my Qt programm on Server A to the the Acron Database on Server B via an ODBC-Driver provided by Videc(Acron), I receive the following error Message:
QSqlError("1010", "QODBC: QODBCResult::reset: Unable to set 'SQL_CURSOR_STATIC' as statement attribute. Please check your ODBC driver configuration", [DataForum][ACRON ODBC Driver]Driver not capable")
What I have tried so far:
I looked into the Logfile of the Acron-Database, but there is not much usefull information to be found:
On the other hand, a powershell-script where I connect to the same Database and executes the same SQL-statement, just works fine ! So I'm not really sure where to look for the problem, since I didn't find anything about the SQL_CURSOR_STATIC attribute in the qt documentation I suspected it to be a Driver-Problem. Attached you will find my code:
main.cpp which fails to retrieve Data
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db;
db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("TestDatabase101");
//db.setConnectOptions("SQL_ATTR_ACCESS_MODE=SQL_MODE_READ_ONLY");
if(db.open()){
qDebug() << "Connected" << Qt::endl;
qDebug() << db.isValid() << Qt::endl;
}
else
qDebug() << "Error" << Qt::endl;
QSqlQuery query(db);
if(!query.exec("SELECT * FROM PV"))
qDebug() << query.lastError() << Qt::endl;
db.close();
return a.exec();
}
AcronConnect.ps1 Powershell-script which just works fine
$conn = New-Object System.Data.Odbc.OdbcConnection
$conn.Connectionstring = "DSN=TestDatabase101"
$conn.Open()
$sql = "SELECT * FROM PV"
$cmd = New-Object System.Data.Odbc.OdbcCommand($sql,$conn)
$da = New-Object System.Data.Odbc.OdbcDataAdapter($cmd)
$dt = New-Object System.Data.DataTable
$null = $da.fill($dt)
$conn.Close()
$dt
Looks like it's a driver issue. It happens during the call to SQLSetStmtAttr() in QODBCResult::reset() where the third parameter can be SQL_CURSOR_STATIC. I would ask the odbc driver vendor to fix this. Maybe debugging into QODBCResult::reset() to see the return value of SQLSetStmtAttr() can help them.