Informix Error -759: Cannot use database commands in an explicit database connection.
Cause and resolution
Cannot use database commands in an explicit database connection.
If you use the CONNECT TO database@server syntax to connect to a database and server, you cannot select another database until you disconnect your current connection.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-759 fires when a session connected via CONNECT TO database@server then attempts a database
selection statement (like DATABASE) to pick a different database — per the official guidance,
once connected this way, changing databases requires disconnecting first, not another selection
statement.
- A session using
CONNECT TO database@serversyntax, then attemptingDATABASE other_database, per the official guidance — the direct, only cause. - Code written assuming the implicit-connection
DATABASE-switching pattern works the same way after an explicitCONNECT TO, when it doesn't.
Solutions / Resolution
- Disconnect the current connection before selecting a different database, per the official
guidance:
DISCONNECT CURRENT; CONNECT TO other_database@server; - If multiple databases genuinely need to be accessed concurrently, use separate named
connections (via
CONNECT TO ... AS connection_name) andSET CONNECTIONto switch between them, rather than trying to reselect a database on the same connection.
Examples
The disallowed attempt
CONNECT TO 'stores7@server_a';
DATABASE other_db;
-- -759: can't select another database on an explicit connection
Corrected — disconnect and reconnect
CONNECT TO 'stores7@server_a';
-- ... work done ...
DISCONNECT CURRENT;
CONNECT TO 'other_db@server_a';
Or corrected — separate named connections
CONNECT TO 'stores7@server_a' AS conn1;
CONNECT TO 'other_db@server_a' AS conn2;
SET CONNECTION conn2;
Diagnostic Checks
- Check whether the session connected via explicit
CONNECT TO, and if so, replace any subsequentDATABASEstatement with a disconnect/reconnect or a separate named connection.
Related Errors / Related Topics
- -758 — "Cannot implicitly reconnect to the new server server_name." A closely related
restriction, about implicitly switching servers rather than databases after an explicit
CONNECT TO.
The same explicit-connection pattern as -758 — disconnect and reconnect, or use separate named
connections with SET CONNECTION.