Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlQuery causing ODBC Function sequence error
Forum Updated to NodeBB v4.3 + New Features

QSqlQuery causing ODBC Function sequence error

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pdsc_dy
    wrote on last edited by
    #1

    I searched this forum, SO, and Google but didn't find much help on this question. 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. Please help...

    • 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;
    }
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi, this looks like https://bugreports.qt.io/browse/QTBUG-54880 - can you please elaborate?

      btw: The ODBC driver does not support QSqlQuery::size() - see http://doc.qt.io/qt-5/qsqldriver.html#DriverFeature-enum

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      4
      • P Offline
        P Offline
        pdsc_dy
        wrote on last edited by
        #3

        @Christian-Ehrlicher Thanks for your quick response. Yes I also noticed the bug report, and tried to apply the query using QSqlQuery::exec(), but still got the same problem. I also tried adding "QCoreApplication::processEvents();" before QSqlQuery. That does not solve the problem either. I have tried everything I can. It does look like a bug but I don't have enough experience to tell whether it's a bug. Can you please help me. Thanks!

        JonBJ 1 Reply Last reply
        0
        • P pdsc_dy

          @Christian-Ehrlicher Thanks for your quick response. Yes I also noticed the bug report, and tried to apply the query using QSqlQuery::exec(), but still got the same problem. I also tried adding "QCoreApplication::processEvents();" before QSqlQuery. That does not solve the problem either. I have tried everything I can. It does look like a bug but I don't have enough experience to tell whether it's a bug. Can you please help me. Thanks!

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @pdsc_dy
          That bug report is against SQL 2005, which is a lot older than 2017. Just saying.

          So they want you to try:

              QSqlQuery query(db);  
              if (!query.exec("SELECT * FROM TBL.tbl_test") ...
          

          ?

          Also what's your TBL referring to?

          P 1 Reply Last reply
          1
          • JonBJ JonB

            @pdsc_dy
            That bug report is against SQL 2005, which is a lot older than 2017. Just saying.

            So they want you to try:

                QSqlQuery query(db);  
                if (!query.exec("SELECT * FROM TBL.tbl_test") ...
            

            ?

            Also what's your TBL referring to?

            P Offline
            P Offline
            pdsc_dy
            wrote on last edited by
            #5

            @JonB I think the user asking the question tried the QSqlQuery query(db) and it worked for him, but not for me.

            TBL is a schema I created in the sql database, using the following coding. Do you think this would cause issues?

            CREATE SCHEMA TBL AUTHORIZATION dbo;
            
            1 Reply Last reply
            0
            • hskoglundH Online
              hskoglundH Online
              hskoglund
              wrote on last edited by
              #6

              Hi, if you're having doubts about your own created database, you could try using Qt for opening one of Microsoft's demo databases, for example the Northwind database

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved