Informix Error -276
-276 Cursor not found.
The cursor that is named in this statement was not declared in the current session. The current session runs from the execution of a DATABASE statement to the next DATABASE or CLOSE DATABASE statement. Review the logic of the program to see that it executes the DECLARE statement for this cursor after the DATABASE statement.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-276 is different from -259's "cursor not open" — this means the cursor was never declared
in the current session at all. The official text defines session boundaries precisely: a
session runs from one DATABASE statement to the next DATABASE or CLOSE DATABASE statement —
a definition with a specific, easy-to-miss consequence.
- Referencing a cursor that was never declared in the current session — distinct from -259, which is about a cursor that was declared (and maybe opened before) but isn't currently open.
- Executing a
DATABASEstatement resets the session, invalidating cursors declared before that switch. Code that declares a cursor, then switches databases, then tries to use the same cursor will hit this — the cursor doesn't survive the database switch. - A typo in the cursor name.
- Statements executed in the wrong order — referencing a cursor before its
DECLAREstatement runs.
Solutions / Resolution
- Review program logic to ensure
DECLAREfor this cursor runs after the currentDATABASEstatement, per the official guidance. - Redeclare any needed cursors after switching databases — a
DATABASEstatement starts a new session, and cursors from the previous session don't carry over. - Check for a typo in the cursor name.
Examples
A database switch invalidating a cursor
DATABASE db1;
DECLARE cur1 CURSOR FOR SELECT * FROM orders;
OPEN cur1;
FETCH cur1 INTO :rec;
DATABASE db2;
-- new session begins here — cur1 no longer exists
FETCH cur1 INTO :rec;
-- -276: cur1 wasn't declared in this session (db2's session)
Fix — redeclare after the switch, if the cursor is still needed:
DATABASE db2;
DECLARE cur1 CURSOR FOR SELECT * FROM some_other_table;
OPEN cur1;
Diagnostic Checks
- Review the sequence of
DATABASE/DECLAREstatements relative to the failing cursor reference — did aDATABASEswitch happen between declaring the cursor and using it? - Check for a typo in the cursor name.
Related Errors / Related Topics
- -259 — "Cursor not open." A different cursor-lifecycle condition — the cursor exists in the current session but isn't currently open, rather than not existing in the session at all.
- -266 — "There is no current row for UPDATE/DELETE cursor." Another cursor-lifecycle condition in the same general family.
Check for an intervening DATABASE statement first — switching databases silently invalidates
cursors declared before the switch.