Informix Error -917: Must close current database before using a new database.
Cause and resolution
Must close current database before using a new database.
This statement (DATABASE or CREATE DATABASE) requires you to open a different database. However, the current database is located on another computer system, so you must explicitly close it with the CLOSE DATABASE statement. (When you work with databases located on the same computer as your application program, the database server will close the current database for you automatically.) If a program receives this error, review the program logic, and check that it executes a CLOSE DATABASE statement before a [CREATE] DATABASE statement. This solution will work in all situations, networked or local.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-917 fires when DATABASE/CREATE DATABASE is issued to open a different database while the
current database (located on another computer system) is still open — per the official guidance,
local databases close automatically when switching, but a database on a different system requires
an explicit CLOSE DATABASE first.
- A program switching databases across systems without an explicit
CLOSE DATABASE, per the official guidance — the direct, only cause; this only applies when the current database is remote, since local databases close implicitly. - Code written and tested only against local databases, where the implicit close masked the need for an explicit one, later failing once it ran against a remote database.
Solutions / Resolution
- Execute a
CLOSE DATABASEstatement before the[CREATE] DATABASEstatement, per the official guidance — this works in all situations, networked or local, so it's a safe universal pattern to adopt. - Review the program logic for every place it switches databases, per the official guidance, and add the explicit close consistently rather than relying on the local-only implicit behavior.
Examples
The disallowed implicit switch
DATABASE sales@remote_server;
-- ... work done ...
DATABASE other_db@remote_server;
-- -917: sales@remote_server is still open (remote databases don't close implicitly)
Corrected — explicit CLOSE DATABASE first
DATABASE sales@remote_server;
-- ... work done ...
CLOSE DATABASE;
DATABASE other_db@remote_server;
Diagnostic Checks
- Check every database-switching point in the program for a preceding explicit
CLOSE DATABASE, adding it universally since it's safe in both local and networked contexts.
Related Errors / Related Topics
- -759 — "Cannot use database commands in an explicit database connection." A related
database-switching restriction, in the
CONNECT TOcontext specifically. - -758 — "Cannot implicitly reconnect to the new server server_name." A related restriction,
about implicit server switching after an explicit
CONNECT TO.
Add an explicit CLOSE DATABASE before every [CREATE] DATABASE statement — safe universally,
required specifically when the current database is remote.