Forum Stats

  • 3,741,184 Users
  • 2,248,385 Discussions


Pro*C software that worked in C fails in C++ : Invalid Cursor


I am working on a slightly big software, in C, that communicates with an Oracle database with Pro*C code. It works fine. Recently, we decided to start a big refactoring work. Part of it is switching our software from C to C++. We succeeded to compile it with g++ and very minor changes. However, I now experience a weird error when opening cursors.

Unfortunately, I can't give you any example of code, because I am unable to reproduce it. All we do is :

EXEC SQL PREPARE my_request FROM request_txt;EXEC SQL DECLARE my_cursor CURSOR FOR my_request;...

only one time


EXEC SQL OPEN my_cursor using :param1, :param2, :param3; // Suceeds a few times then fail and never works again...while (no_error){  EXEC SQL FETCH my_cursor INTO :data1, :data2, :data3, :data4;  ...}...EXEC SQL CLOSE my_cursor; // checked every time, no error (not executed if the opening failed).

The error is "ORA-01001, invalid cursor" (with SQL State 24000). In found documentation about it, but it doesn't seem to apply to my case.

Indeed, I am able to open/close the same cursor several time before it fails to open. I am 100% sure that the cursor is closed before reopening. A few cursors are already opened when executing these lines, and a few fetchs are done on them between two calls of my function. But I mean, the exact same code works fine in C !

The request itself is pretty simple : a select in a single View using three parameters.

The weird thing is that this error happens every time on the same data for the same input. But when the data is put inside an other (larger or smaller) input, the error generally happens on an other data, before or after the previous one.

Another interesting point : I tried to move the Pro*C code in separate functions in separate files. And it worked ! The error did not happen on the request. However, the exact same error happened on another request elsewhere. I don't want to move that code too because I am pretty sure the error will then move somewhere else, and I don't want to move the hundreds of different requests used in our soft in separate files.

We tried many many things.

I put logs everywhere, and all of them gave a quite normal behavior of the control flow of the program

I tried to augment the MAXOPENCURSORS parameter to 200, no change (and it worked fine in C with the default parameter)

I tried to put HOLD_CURSOR and RELEASE_CURSOR to YES and NO, no change

I tried to put a sleep after each CLOSE instruction to make sure Oracle has the time to close the cursor, no change (but slower program)

I tried to randomly change compilation options (ANSI mode, Oracle mode...). No change, or failure to connect.

I tried to run a D.side on the database while running the program, but I were unable to find any useful information, I mean no traces on what happens on the database.

I tried to move the Pro*C part of the code in a single file, the error happened elsewhere. I moved that other piece of code in a single file too, it happened again somewhere else (but the requests are now correctly executed, excepted the one failing).

I am out of solutions. Furthermore, I can't post a single piece of real code because when separated from the rest of the program, theses requests works fine in C and C++ !

The only substantial difference between the two cases is the compiler : gcc -> g++. I am pretty sure my problem comes from the C++ switching. Do you had any case similar to mine please ? Or, do you have an idea about a good way to trace my database, monitor my cursors, or tracks every error returned by oracle and why they happened ?

I run my code on a Redhat 5, under Linux 2.6.18-402.el5 #1 SMP Thu Jan 8 06:22:34 EST 2015 x86_64 x86_64 x86_64 GNU/Linux.

My compiler is on version 4.1.2. (I cannot change these).

Thank you very much,

This discussion has been closed.