{"record":{"id":"ea05bc7e25c547f3","repo":"OtterMind/Chat2DB","slug":"database-delete-connectiondatabasemismatch","errorCode":"database.delete.connectionDatabaseMismatch","errorMessage":"database.delete.connectionDatabaseMismatch","messagePattern":"database\\.delete\\.connectionDatabaseMismatch","errorType":"validation","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbDatabaseObjectDeleteServiceImpl.java","lineNumber":133,"sourceCode":"            Chat2DBContext.getDbManager(dbType).dropDatabase(connection, databaseName);\n        } catch (BusinessException e) {\n            throw e;\n        } catch (Exception e) {\n            throw new BusinessException(\"database.delete.executeFailed\", new Object[]{e.getMessage()}, e);\n        }\n    }\n\n    @Override\n    public void executeSchemaDelete(DbDatabaseObjectDeleteExecuteRequest param) {\n        ConnectionProfile profile = requireCurrentProfile();\n        String dbType = requireSupportedDbType(profile);\n        String databaseName = requireName(param.getDatabaseName(), \"databaseName\");\n        String schemaName = requireName(param.getSchemaName(), \"schemaName\");\n        assertSchemaDeletionSupported(dbType);\n        rejectSystemSchema(dbType, schemaName);\n        assertConfirmName(param.getConfirmName(), schemaConfirmName(schemaName));\n        if (!StringUtils.equals(profile.getDatabaseName(), databaseName)) {\n            throw new BusinessException(\"database.delete.connectionDatabaseMismatch\");\n        }\n        Connection connection = requireConnection();\n        try {\n            assertSchemaExists(connection, databaseName, schemaName);\n            Chat2DBContext.getDbManager(dbType).dropSchema(connection, databaseName, schemaName);\n        } catch (BusinessException e) {\n            throw e;\n        } catch (Exception e) {\n            throw new BusinessException(\"database.delete.executeFailed\", new Object[]{e.getMessage()}, e);\n        }\n    }\n\n    private ConnectionProfile requireCurrentProfile() {\n        ConnectionProfile profile = connectionContextService.currentProfile();\n        if (profile == null) {\n            throw new BusinessException(\"database.delete.invalidDataSource\");\n        }\n        return profile;","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbDatabaseObjectDeleteServiceImpl.java#L115-L151","documentation":"Thrown by executeSchemaDelete() when profile.getDatabaseName() does NOT equal the requested databaseName. Schema deletion must target the database the current connection is actually bound to, so a mismatch is rejected.","triggerScenarios":"A drop-schema execute request names a database different from the connection's current database. Unlike database delete, schema delete does not rebind, so the connection's database must already match.","commonSituations":"Frontend sends a schema-delete for a database other than the connected one; profile is stale after a switch; mismatched databaseName casing for case-sensitive dialects.","solutions":["Switch/rebind the connection to the target database (rebindCurrentDatabase) before issuing executeSchemaDelete.","Confirm the request's databaseName exactly matches profile.getDatabaseName() (mind case-sensitivity).","Re-prepare from the correct database context."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before executeSchemaDelete\nConnectionProfile profile = connectionContextService.currentProfile();\nif (profile == null || !StringUtils.equals(profile.getDatabaseName(), param.getDatabaseName())) {\n    // rebind/switch to the target database first\n    return Result.fail(\"database.delete.connectionDatabaseMismatch\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Switch the connection to the target database before schema deletion.","Mind case-sensitivity when comparing database names on some dialects.","Re-prepare from the correct database context."],"tags":["database","delete","schema","ddl","connection","mismatch"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}