{"record":{"id":"2d6d5fd5b9cd3c04","repo":"pentaho/pentaho-kettle","slug":"this-database-is-still-in-use-by-n-jobs-and-m","errorCode":null,"errorMessage":"This database is still in use by N jobs and M transformations references","messagePattern":"This database is still in use by N jobs and M transformations references","errorType":"exception","errorClass":"KettleDependencyException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryDatabaseDelegate.java","lineNumber":386,"sourceCode":"    if ( jobList.length == 0 && transList.length == 0 ) {\n      repository.connectionDelegate.performDelete( \"DELETE FROM \"\n        + quoteTable( KettleDatabaseRepository.TABLE_R_DATABASE ) + \" WHERE \"\n        + quote( KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE ) + \" = ? \", id_database );\n    } else {\n      String message = \" Database used by the following \" + Const.CR;\n      if ( jobList.length > 0 ) {\n        message = \"jobs :\" + Const.CR;\n        for ( String job : jobList ) {\n          message += \"\\t \" + job + Const.CR;\n        }\n      }\n\n      message += \"transformations:\" + Const.CR;\n      for ( String trans : transList ) {\n        message += \"\\t \" + trans + Const.CR;\n      }\n      KettleDependencyException e = new KettleDependencyException( message );\n      throw new KettleDependencyException( \"This database is still in use by \"\n        + jobList.length + \" jobs and \" + transList.length + \" transformations references\", e );\n    }\n  }\n\n  public synchronized void delDatabaseAttributes( ObjectId id_database ) throws KettleException {\n    repository.connectionDelegate.performDelete( \"DELETE FROM \"\n      + quoteTable( KettleDatabaseRepository.TABLE_R_DATABASE_ATTRIBUTE ) + \" WHERE \"\n      + quote( KettleDatabaseRepository.FIELD_DATABASE_ATTRIBUTE_ID_DATABASE ) + \" = ? \", id_database );\n  }\n\n  public synchronized int getNrDatabases() throws KettleException {\n    int retval = 0;\n\n    String sql = \"SELECT COUNT(*) FROM \" + quoteTable( KettleDatabaseRepository.TABLE_R_DATABASE );\n    RowMetaAndData r = repository.connectionDelegate.getOneRow( sql );\n    if ( r != null ) {\n      retval = (int) r.getInteger( 0, 0L );\n    }","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryDatabaseDelegate.java#L368-L404","documentation":"A KettleDependencyException thrown by delDatabase when the database connection being deleted is still referenced by jobs and/or transformations in the repository. The message counts the referencing jobs and transformations and attaches a detailed exception listing every dependent by name, so the delete is refused to preserve referential integrity.","triggerScenarios":"Calling delDatabase(id_database) (via deleteDatabaseMeta) while rows in the job/transformation database-association tables still reference the connection id.","commonSituations":"Removing a shared database connection still used by scheduled jobs; cleaning up unused connections without first checking usage; after importing content that references the connection.","solutions":["Open the dependent jobs/transformations listed in the cause message and re-point or remove their database usage","Re-save those jobs/transformations, then retry the delete","If the references are stale/orphan rows, clean the association tables manually after backing up the repository","Delete or archive the dependent jobs/transformations if they are no longer needed"],"exampleFix":"// before\nrepository.deleteDatabaseMeta(\"SharedConn\"); // throws dependency exception\n// after: re-point dependents first\nfor (String trans : dependentTransformations) {\n  // load each transformation, change its DB connection, re-save\n}\nrepository.deleteDatabaseMeta(\"SharedConn\");","handlingStrategy":"validation","validationCode":"// check references before deleting a connection\nResultSet rs = stmt.executeQuery(\n  \"SELECT COUNT(*) FROM R_JOB_ATTRIBUTE WHERE CODE='DATABASE_NAME' AND VALUE_STR='SharedConn'\");","typeGuard":null,"tryCatchPattern":"try {\n  repository.deleteDatabaseMeta(name);\n} catch (KettleDependencyException e) {\n  // parse dependent job/transformation names from e.getMessage() and re-point them first\n}","preventionTips":["Audit jobs/transformations referencing a connection before deleting it","Maintain a naming/ownership registry for shared connections","Prefer re-pointing dependents to a new connection instead of hard deletes"],"tags":["database","repository","dependency","delete","referential-integrity"],"backgroundTag":"conflicting-config-options","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}