t8y2/dbx · error · IllegalStateException

Not connected

Error message

Not connected

What it means

executeQueryPage() checks getConnection() before handing the SQL to the JDBC executor. If no connection is established (never connected, disconnected, or the connection was lost and set to null), it throws IllegalStateException("Not connected") instead of attempting a query on a null Connection.

Source

Thrown at agents/common/src/main/java/com/dbx/agent/DatabaseAgent.java:163

    List<ForeignKeyInfo> listForeignKeys(String schema, String table);

    List<TriggerInfo> listTriggers(String schema, String table);

    default QueryResult executeQuery(String sql, String schema) {
        return executeQuery(sql, schema, new ExecuteQueryOptions());
    }

    QueryResult executeQuery(String sql, String schema, ExecuteQueryOptions options);

    default QueryPageResult executeQueryPage(String sql, String schema) {
        return executeQueryPage(sql, schema, new QueryPageOptions());
    }

    default QueryPageResult executeQueryPage(String sql, String schema, QueryPageOptions options) {
        Connection conn = getConnection();
        if (conn == null) {
            throw new IllegalStateException("Not connected");
        }
        return AgentExecutionContext.jdbcExecutor().executePage(
            conn,
            sql,
            schema,
            this::setSchemaSQL,
            this::resetSchemaSQL,
            options,
            AgentExecutionContext.jdbcExecutor()::defaultResultValue
        );
    }

    default QueryPageResult fetchQueryPage(String sessionId, int pageSize) {
        return AgentExecutionContext.jdbcExecutor().fetchPage(sessionId, pageSize);
    }

    default boolean closeQuerySession(String sessionId) {
        return AgentExecutionContext.jdbcExecutor().closeQuerySession(sessionId);

View on GitHub (pinned to c0390bff16)

Solutions

  1. Call connect(params) (and verify testConnection succeeds) before issuing executeQueryPage.
  2. Before querying, validate agent.getConnection() != null and reconnect if null.
  3. Catch IllegalStateException and trigger a reconnect + retry of the paged query.
  4. Investigate why the connection is null (network drop, server restart, driver timeout) and add reconnect-on-failure logic.

Example fix

// before
QueryPageResult r = agent.executeQueryPage(sql, schema);
// after
if (agent.getConnection() == null) {
    agent.connect(params);
}
QueryPageResult r = agent.executeQueryPage(sql, schema);
Defensive patterns

Strategy: validation

Validate before calling

if (agent.getConnection() == null) {
    agent.connect(params); // or throw a friendly 'reconnect required' error
}

Type guard

static boolean isConnected(DatabaseAgent a) {
    return a.getConnection() != null;
}

Try / catch

try {
    return agent.executeQueryPage(sql, schema, options);
} catch (IllegalStateException e) {
    if (e.getMessage().contains("Not connected")) {
        agent.connect(params);
        return agent.executeQueryPage(sql, schema, options);
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling executeQueryPage(sql, schema) or executeQueryPage(sql, schema, options) before connect() succeeded, after disconnect(), or when the agent implementation's getConnection() returns null because the underlying connection died and was not re-established.

Common situations: App started paging queries before the connect call completed; the database restarted and the agent's stored connection is null; a long-lived session was disconnected by a timeout and pagination is attempted afterwards.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/7de329e50d329ccb. Report an issue: GitHub.