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. QODBC SQL Server sp_cursoropen "The cursor was not declared" error
QtWS25 Last Chance

QODBC SQL Server sp_cursoropen "The cursor was not declared" error

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 989 Views
  • 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.
  • R Offline
    R Offline
    Rudl
    wrote on 17 Oct 2018, 19:58 last edited by
    #1

    I am using QODBC to connect to MS SQL Server. Everything works fine with normal Statements, executing stored procedures, that I've created in SQL Server and so on... Now I created a stored procedure in Visual Studio and did implement it via common language runtime (CLR) into SQL Server. It creates me an assembly and a stored procedure in SQL Server. I can execute this stored procedure in SQL Server Management Studio without any problem. But when I called it from my QT programm it throws the error:

    [Microsoft][SQL Server Native Client 11.0][SQL Server]The request for procedure 'HelloWorldExp' failed because 'HelloWorldExp' is a procedure object. [Microsoft][SQL Server Native Client 11.0][SQL Server]The cursor was not declared. QODBC3: Unable to execute statement
    

    I did some research and found the request in SQl Server profiler. In SQL Server Profiler the SQL request lokks like this:

    declare @p1 int
    set @p1=0
    declare @p3 int
    set @p3=8
    declare @p4 int
    set @p4=8193
    declare @p5 int
    set @p5=0
    exec sp_cursoropen @p1 output,N'EXEC HelloWorldExp ''1''',@p3 output,@p4 output,@p5 output
    select @p1, @p3, @p4, @p5
    

    When I use another sample programm using ODBC without QT, the SQl request looks like:

    HelloWorldExp ''1'''
    

    This will be executes without any error.

    Is there a setting that tells QT not to send the whole overhead?

    J 1 Reply Last reply 17 Oct 2018, 21:10
    0
    • R Rudl
      17 Oct 2018, 19:58

      I am using QODBC to connect to MS SQL Server. Everything works fine with normal Statements, executing stored procedures, that I've created in SQL Server and so on... Now I created a stored procedure in Visual Studio and did implement it via common language runtime (CLR) into SQL Server. It creates me an assembly and a stored procedure in SQL Server. I can execute this stored procedure in SQL Server Management Studio without any problem. But when I called it from my QT programm it throws the error:

      [Microsoft][SQL Server Native Client 11.0][SQL Server]The request for procedure 'HelloWorldExp' failed because 'HelloWorldExp' is a procedure object. [Microsoft][SQL Server Native Client 11.0][SQL Server]The cursor was not declared. QODBC3: Unable to execute statement
      

      I did some research and found the request in SQl Server profiler. In SQL Server Profiler the SQL request lokks like this:

      declare @p1 int
      set @p1=0
      declare @p3 int
      set @p3=8
      declare @p4 int
      set @p4=8193
      declare @p5 int
      set @p5=0
      exec sp_cursoropen @p1 output,N'EXEC HelloWorldExp ''1''',@p3 output,@p4 output,@p5 output
      select @p1, @p3, @p4, @p5
      

      When I use another sample programm using ODBC without QT, the SQl request looks like:

      HelloWorldExp ''1'''
      

      This will be executes without any error.

      Is there a setting that tells QT not to send the whole overhead?

      J Online
      J Online
      JonB
      wrote on 17 Oct 2018, 21:10 last edited by JonB
      #2

      @Rudl
      This looks like a nasty one. I don't know whether you can cause Qt to issue different SQL code (how exactly does your code call the procedure?). And I'm not sure even if you did it would affect the behaviour. It sounds like it ought to be working.

      I know this sounds lame, but have you tried restarting your SQL Server since you first got this error and try again on a freshly connected database?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rudl
        wrote on 20 Oct 2018, 16:54 last edited by
        #3

        Thank you for your replay.

        I call the procedure like this:

        QSqlQuery query;
            query.exec("EXEC HelloWorldExp '1' ");
        

        Of course, when I execute this code on SQL Server directly:

        declare @p1 int
        set @p1=0
        declare @p3 int
        set @p3=8
        declare @p4 int
        set @p4=8193
        declare @p5 int
        set @p5=0
        exec sp_cursoropen @p1 output,N'EXEC HelloWorldExp ''1''',@p3 output,@p4 output,@p5 output
        select @p1, @p3, @p4, @p5
        

        I get the same error. When I execute just:

        EXEC HelloWorldExp '1' 
        

        everything works fine.

        I did restart the SQL Server and I have the same effect.

        When I create the stored procedure in Visual Studio and implement it via CLR into SQL Server, the stored procedure is protected.
        So I can't see or change the stored procedure. With the workaround to create another stored procedure in SQL Management Studio, that calls the "HelloWorldExp" it works.

        It seams sp_cursoropen has a problem with CLR created procedures.

        1 Reply Last reply
        0

        2/3

        17 Oct 2018, 21:10

        • Login

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