{"record":{"id":"e57724abd6cfa1f2","repo":"pentaho/pentaho-kettle","slug":"error-loading-database-connection-from-repository-id","errorCode":null,"errorMessage":"Error loading database connection from repository (id_database={id_database})","messagePattern":"Error loading database connection from repository \\(id_database=(.+?)\\)","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryDatabaseDelegate.java","lineNumber":146,"sourceCode":"        databaseMeta.setUsername( r.getString( KettleDatabaseRepository.FIELD_DATABASE_USERNAME, \"\" ) );\n        databaseMeta.setPassword( Encr.decryptPasswordOptionallyEncrypted( r.getString(\n          KettleDatabaseRepository.FIELD_DATABASE_PASSWORD, \"\" ) ) );\n        databaseMeta.setServername( r.getString( KettleDatabaseRepository.FIELD_DATABASE_SERVERNAME, \"\" ) );\n        databaseMeta.setDataTablespace( r.getString( KettleDatabaseRepository.FIELD_DATABASE_DATA_TBS, \"\" ) );\n        databaseMeta.setIndexTablespace( r.getString( KettleDatabaseRepository.FIELD_DATABASE_INDEX_TBS, \"\" ) );\n\n        // Also, load all the properties we can find...\n        final Collection<RowMetaAndData> attrs = repository.connectionDelegate.getDatabaseAttributes( id_database );\n        for ( RowMetaAndData row : attrs ) {\n          String code = row.getString( KettleDatabaseRepository.FIELD_DATABASE_ATTRIBUTE_CODE, \"\" );\n          String attribute = row.getString( KettleDatabaseRepository.FIELD_DATABASE_ATTRIBUTE_VALUE_STR, \"\" );\n          databaseMeta.getAttributes().put( code, Const.NVL( attribute, \"\" ) );\n        }\n      }\n\n      return databaseMeta;\n    } catch ( KettleDatabaseException dbe ) {\n      throw new KettleException( \"Error loading database connection from repository (id_database=\"\n        + id_database + \")\", dbe );\n    }\n  }\n\n  /**\n   * Saves the database information into a given repository.\n   *\n   * @param databaseMeta\n   *          The database metadata object to store\n   *\n   * @throws KettleException\n   *           if an error occurs.\n   */\n  public void saveDatabaseMeta( DatabaseMeta databaseMeta ) throws KettleException {\n    try {\n      // If we don't have an ID, we don't know which entry in the database we need to update.\n      // See if a database with the same name is already available...\n      if ( databaseMeta.getObjectId() == null ) {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryDatabaseDelegate.java#L128-L164","documentation":"Wraps a KettleDatabaseException raised while reconstructing a DatabaseMeta object from the R_DATABASE and R_DATABASE_ATTRIBUTE tables for a given id_database. The message names the offending id so the broken row can be located. Cause is the underlying database exception.","triggerScenarios":"Calling loadDatabaseMeta(id_database) when reading the R_DATABASE row or its attributes throws: missing/corrupt row, SQL error, or a bad attribute value preventing DatabaseMeta construction.","commonSituations":"Referencing a database connection id that no longer exists (stale id from another environment); corrupted R_DATABASE rows after a failed import; attribute rows lost after a partial delete/re-insert cycle.","solutions":["Verify a row with that id exists in R_DATABASE (query by id_database from the message)","Check R_DATABASE_ATTRIBUTE rows for the id and re-enter the connection in Repository Explorer if corrupt","Re-import or recreate the database connection and update the referencing object","Inspect the cause KettleDatabaseException for the SQL-level failure"],"exampleFix":"// before: trust the stored id\nDatabaseMeta db = databaseDelegate.loadDatabaseMeta(staleId);\n// after: resolve id by name and handle absence\nObjectId id = databaseDelegate.getDatabaseID(\"MyConnection\");\nif (id != null) {\n  DatabaseMeta db = databaseDelegate.loadDatabaseMeta(id);\n}","handlingStrategy":"validation","validationCode":"// confirm the connection id exists before loading\nPreparedStatement ps = conn.prepareStatement(\"SELECT COUNT(*) FROM R_DATABASE WHERE ID_DATABASE = ?\");\nps.setInt(1, idDatabase);\nif (rsCount(ps) == 0) { throw new IllegalStateException(\"Database connection id \" + idDatabase + \" not in repository\"); }","typeGuard":"ObjectId id = databaseDelegate.getDatabaseID(name);\nif (id == null) { return null; } // or throw a clear not-found error","tryCatchPattern":"try {\n  DatabaseMeta meta = delegate.loadDatabaseMeta(id);\n} catch (KettleException e) {\n  log.error(\"Load failed for id_database=\" + id, e.getCause());\n}","preventionTips":["Resolve connection ids by name at runtime instead of hard-coding ids","Recreate connections via Repository Explorer if attribute rows look stale","Back up R_DATABASE/R_DATABASE_ATTRIBUTE before imports"],"tags":["database","repository","database-meta","load"],"backgroundTag":"record-not-found","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"}