Informix Error -349: Database not selected yet.
Cause and resolution
Database not selected yet.
This statement cannot be executed because no current database exists. Either no current database has been established yet, or the current database was closed with a CLOSE DATABASE statement. You execute the DATABASE or CREATE DATABASE statement to establish a current database.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-349 is a straightforward session-state error: a statement was submitted without a current
database established — either the session never issued DATABASE/CREATE DATABASE at all, or a
prior CLOSE DATABASE ended the current database context without a follow-up DATABASE
statement.
- A script or session issuing SQL statements before ever running
DATABASE/CREATE DATABASE— the most common cause in ad-hoc or newly-written scripts. - A
CLOSE DATABASEstatement executed earlier in the session, followed by further statements without re-selecting a database. - A connection-pooling or session-reuse setup where a previous operation on the same connection closed the database context, and the reuse logic doesn't re-select one before the next statement.
- An error-handling path that closes the database on failure, but a subsequent retry attempt doesn't re-establish it first.
Solutions / Resolution
- Issue
DATABASE database_name;(orCREATE DATABASE) before running other statements, per the official guidance, to establish the current database context. - Check for an earlier
CLOSE DATABASEin the same session if this appears partway through a script that previously worked. - For connection-pooling setups, ensure each borrowed connection re-selects its database before use, rather than assuming a database context persists across reuse.
Examples
Selecting a database before running statements
DATABASE sales;
SELECT * FROM orders;
A CLOSE DATABASE breaking subsequent statements
DATABASE sales;
SELECT * FROM orders;
CLOSE DATABASE;
SELECT * FROM customers;
-- -349: no current database after CLOSE DATABASE
Fix — re-select the database before continuing:
DATABASE sales;
SELECT * FROM orders;
CLOSE DATABASE;
DATABASE sales;
SELECT * FROM customers;
Diagnostic Checks
- Review the script/session for a
DATABASE/CREATE DATABASEstatement before the failing statement. - Check for an earlier
CLOSE DATABASEin the same session with no subsequent re-selection.
Related Errors / Related Topics
- -329 — "Database not found or no system permission." A related database-selection error, though about the database not being reachable at all rather than simply never having been selected.
Every session needs an active DATABASE/CREATE DATABASE context before other statements can
run — check for a missing initial selection or an earlier CLOSE DATABASE first.