It seems due to ODBC functions being called out out of order. But since I am using QSql that wraps ODBC, it is hard for me to track down the function.
- I was able to connect to the SQL server database
- I tested a very simply query and still got the error. I don't think it's due to column binding.
- I was able to run the query with SQL server, so I think the SQL query is ok.
- The tools I am using:
VS c++ 2017, CMake, Qt 5.09.2, SQL server 2017
- Below are the error messages:
QODBCResult::exec: Unable to execute statement: "[Microsoft][ODBC Driver Manager] Function sequence error"
QSqlError("0", "QODBC3: Unable to execute statement", "[Microsoft][ODBC Driver Manager] Function sequence error")
Test coding:
This coding generate the error message above.
int main() { QSqlDatabase GUIInpDB = QSqlDatabase::addDatabase("QODBC", "MainSQLDB"); GUIInpDB.setConnectOptions(); QString inpSqlServer = "DESKTOP-085AEA8\\SQLEXPRESS"; QString dbName = "test"; QString connString = QString("Driver={ODBC Driver 13 for SQL Server};Server=%1;DATABASE=%2;Trusted_Connection=Yes;") .arg(inpSqlServer).arg(dbName); //the argument replace the %1 and %2 GUIInpDB.setDatabaseName(connString); QSqlDatabase db = QSqlDatabase::database("MainSQLDB"); if (!db.open()) { qDebug() << "Connection for db not working"; return 1; } QSqlQuery query("SELECT * FROM TBL.tbl_test", db); if (!query.exec()) qDebug() << query.lastError(); int num_of_rows = query.size(); getchar(); return 0; }