Informix Error -586
Cause and resolution
Cursor is already open.
This database is operating in ANSI compliance (it was created or started MODE ANSI). By the rules of ANSI SQL, a cursor must always be closed before it can be reopened. Review the logic of the program. Possibly it was originally written to take advantage of one of the IBM Informix extensions to SQL: if a cursor is reopened, it is automatically closed and opened. In the current database, that action is not allowed.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-586 fires when OPEN is issued against a cursor that's already open, in a database running in
ANSI-compliant mode (MODE ANSI) — per the official guidance, standard ANSI SQL requires a
cursor to be closed before it can be reopened; the automatic close-then-open behavior available
as an IBM Informix extension in non-ANSI databases isn't allowed here.
- A program relying on the Informix extension of implicitly closing and reopening an already-open cursor, per the official guidance — written for (or carried over from) a non-ANSI database, where that convenience is available.
- A missing
CLOSE cursor-namebefore a secondOPENin a retry or loop, that happened to work by accident on a non-ANSI database but fails once the database is ANSI-compliant. - A cursor opened once at program start and mistakenly reopened later, rather than reused
via
FETCHafter its initial open.
Solutions / Resolution
- Add an explicit
CLOSE cursor-namebefore theOPEN, per the official guidance, since ANSI compliance requires this to be done explicitly rather than automatically:CLOSE order_cursor; OPEN order_cursor; - Review the program's cursor lifecycle logic, per the official guidance, particularly any
retry or loop structure that might call
OPENmore than once without an interveningCLOSE. - Confirm whether the database is genuinely meant to be ANSI-compliant, if relying on the
Informix auto-close/open extension was actually intended — that convenience simply isn't
available once a database is
MODE ANSI.
Examples
Relying on the extension, which fails under ANSI mode
OPEN order_cursor;
-- ... fetch loop ...
OPEN order_cursor; -- intended to restart the cursor
-- -586: ANSI-compliant database requires an explicit CLOSE first
Corrected — explicit CLOSE before reopening
OPEN order_cursor;
-- ... fetch loop ...
CLOSE order_cursor;
OPEN order_cursor;
Diagnostic Checks
- Confirm whether the database is ANSI-compliant (
MODE ANSI), since this restriction only applies there. - Scan for any
OPENon a cursor without a precedingCLOSE, especially inside loops or retry logic, once ANSI mode is confirmed.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -586 in this set yet.
An ANSI-compliant database requires an explicit CLOSE before reopening a cursor — the
Informix auto-close/open convenience isn't available there.