OtterMind/Chat2DB · error · BusinessException

database.delete.connectionTargetsDeletedDatabase

database.delete.connectionTargetsDeletedDatabase

Error message

database.delete.connectionTargetsDeletedDatabase

What it means

Thrown by executeDatabaseDelete() when the current connection's database (profile.getDatabaseName()) equals the database being deleted. Dropping the database you are currently connected to is refused as a safety guard.

Source

Thrown at chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbDatabaseObjectDeleteServiceImpl.java:110

            throw e;
        } catch (Exception e) {
            throw new BusinessException("database.delete.prepareFailed", new Object[]{e.getMessage()}, e);
        }
        return prepareResult(schemaConfirmName(schemaName), buildDropSchema(dbType, schemaName), TYPE_SCHEMA, dbType);
    }

    @Override
    public void executeDatabaseDelete(DbDatabaseObjectDeleteExecuteRequest param) {
        ConnectionProfile profile = requireCurrentProfile();
        String dbType = requireSupportedDbType(profile);
        reconnectForDatabaseDelete(dbType);
        profile = requireCurrentProfile();
        String databaseName = requireName(param.getDatabaseName(), "databaseName");
        assertDatabaseDeletionSupported(dbType);
        rejectSystemDatabase(dbType, databaseName);
        assertConfirmName(param.getConfirmName(), databaseConfirmName(databaseName));
        if (StringUtils.equals(profile.getDatabaseName(), databaseName)) {
            throw new BusinessException("database.delete.connectionTargetsDeletedDatabase");
        }
        Connection connection = requireConnection();
        try {
            assertDatabaseExists(connection, dbType, databaseName);
            Chat2DBContext.getDbManager(dbType).dropDatabase(connection, databaseName);
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            throw new BusinessException("database.delete.executeFailed", new Object[]{e.getMessage()}, e);
        }
    }

    @Override
    public void executeSchemaDelete(DbDatabaseObjectDeleteExecuteRequest param) {
        ConnectionProfile profile = requireCurrentProfile();
        String dbType = requireSupportedDbType(profile);
        String databaseName = requireName(param.getDatabaseName(), "databaseName");
        String schemaName = requireName(param.getSchemaName(), "schemaName");

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. Ensure the connection is rebound to a different maintenance database before drop (reconnectForDatabaseDelete handles PostgreSQL; add equivalent handling for the dialect if missing).
  2. Verify profile.getDatabaseName() differs from the target databaseName before issuing executeDatabaseDelete.
  3. For PostgreSQL confirm maintenanceDatabase() returns a DB other than the target.
Defensive patterns

Strategy: validation

Validate before calling

// Before executeDatabaseDelete
ConnectionProfile profile = connectionContextService.currentProfile();
if (profile != null && StringUtils.equals(profile.getDatabaseName(), param.getDatabaseName())) {
    // rebind to a maintenance database first (PostgreSQL path), or refuse
    return Result.fail("database.delete.connectionTargetsDeletedDatabase");
}

Prevention

When it happens

Trigger: A drop-database execute request targets the same database the connection context is bound to. For PostgreSQL, reconnectForDatabaseDelete rebinds to a maintenance database; if that rebind did not move off the target (or dbType is not PostgreSQL), the guard trips.

Common situations: Non-PostgreSQL dialects that don't rebind, or PostgreSQL where the maintenance database equals the target; a stale profile after a failed rebind; the user picks the database the session is logged into.

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/be60767894e932d2. Report an issue: GitHub.