{"record":{"id":"71f20f2780de09b8","repo":"pentaho/pentaho-kettle","slug":"dynamicsqlrowmeta-exception-errorobtainingfields","errorCode":null,"errorMessage":"DynamicSQLRowMeta.Exception.ErrorObtainingFields","messagePattern":"DynamicSQLRowMeta\\.Exception\\.ErrorObtainingFields","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/dynamicsqlrow/DynamicSQLRowMeta.java","lineNumber":258,"sourceCode":"    if ( add != null ) { // Cache hit, just return it this...\n      for ( int i = 0; i < add.size(); i++ ) {\n        ValueMetaInterface v = add.getValueMeta( i );\n        v.setOrigin( name );\n      }\n      row.addRowMeta( add );\n    } else {\n      // No cache hit, connect to the database, do it the hard way...\n      try {\n        db.connect();\n        add = db.getQueryFields( realSQL, false );\n        for ( int i = 0; i < add.size(); i++ ) {\n          ValueMetaInterface v = add.getValueMeta( i );\n          v.setOrigin( name );\n        }\n        row.addRowMeta( add );\n        db.close();\n      } catch ( KettleDatabaseException dbe ) {\n        throw new KettleStepException( BaseMessages.getString(\n          PKG, \"DynamicSQLRowMeta.Exception.ErrorObtainingFields\" ), dbe );\n      }\n    }\n  }\n\n  public String getXML() {\n    StringBuilder retval = new StringBuilder();\n\n    retval\n      .append( \"    \" + XMLHandler.addTagValue( \"connection\", databaseMeta == null ? \"\" : databaseMeta.getName() ) );\n    retval.append( \"    \" + XMLHandler.addTagValue( \"rowlimit\", rowLimit ) );\n    retval.append( \"    \" + XMLHandler.addTagValue( \"sql\", sql ) );\n    retval.append( \"    \" + XMLHandler.addTagValue( \"outer_join\", outerJoin ) );\n    retval.append( \"    \" + XMLHandler.addTagValue( \"replace_vars\", replacevars ) );\n    retval.append( \"    \" + XMLHandler.addTagValue( \"sql_fieldname\", sqlfieldname ) );\n    retval.append( \"    \" + XMLHandler.addTagValue( \"query_only_on_change\", queryonlyonchange ) );\n\n    return retval.toString();","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/dynamicsqlrow/DynamicSQLRowMeta.java#L240-L276","documentation":"DynamicSQLRowMeta.getFields wraps a KettleDatabaseException raised while finalizing the step's output fields (attaching the query-derived fields to the row meta and closing the connection) into a KettleStepException with this message key. Unlike 1388, this fires after getQueryFields succeeded, during the add/close phase.","triggerScenarios":"In getFields, after add = db.getQueryFields(...) returned, when subsequent operations inside the try block (e.g. db.close() or value metadata handling) throw KettleDatabaseException — typically connection close/rollback failures.","commonSituations":"Connection already dropped between query-field retrieval and close (network timeout, DB killed session); driver quirks on close; pool exhaustion.","solutions":["Check the wrapped cause for the close/connection error; inspect DB logs for dropped sessions","Verify network stability and connection/timeout settings on the database connection","Update the JDBC driver to a version compatible with the DB server","Retry the metadata calculation; if transient, the error should not recur"],"exampleFix":"// before\n// connection closed abruptly by firewall after 30s idle\n// after\nset 'Connection timeout' / TCP keepalive on the DB connection (e.g. connectTimeout=30000, socketTimeout=0) and ensure firewall idle timeout > query duration","handlingStrategy":"try-catch","validationCode":"// Verify the connection is usable before field calculation:\nDatabase db = new Database(loggingObject, meta.getDatabaseMeta());\ndb.connect();\nif (!db.checkConnection()) throw new IllegalStateException(\"DB connection check failed\");\ndb.disconnect();","typeGuard":null,"tryCatchPattern":"try {\n  meta.getFields(row, origin, info, target, space, repository, metaStore);\n} catch (KettleStepException e) {\n  logError(\"Error obtaining fields — check DB connection stability: \" + e.getCause(), e);\n  throw e;\n}","preventionTips":["Tune connection timeouts and keepalives for long analyses","Update JDBC drivers to match the server version","Avoid idle connections through firewalls during analysis","Retry transient failures during impact analysis runs"],"tags":["kettle","database","connection"],"backgroundTag":"database-query-failed","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"}