{"record":{"id":"90144baf2c226b76","repo":"pentaho/pentaho-kettle","slug":"trans-exception-errorconnectingtodatabase","errorCode":null,"errorMessage":"Trans.Exception.ErrorConnectingToDatabase","messagePattern":"Trans\\.Exception\\.ErrorConnectingToDatabase","errorType":"exception","errorClass":"KettleTransException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/Trans.java","lineNumber":2342,"sourceCode":"              String sql = \"SELECT MAX(\" + transMeta.getMaxDateField() + \") FROM \" + transMeta.getMaxDateTable();\n              RowMetaAndData r1 = maxdb.getOneRow( sql );\n              if ( r1 != null ) {\n                // OK, we have a value, what's the offset?\n                Date maxvalue = r1.getRowMeta().getDate( r1.getData(), 0 );\n                if ( maxvalue != null ) {\n                  if ( log.isDetailed() ) {\n                    log.logDetailed( BaseMessages.getString( PKG, \"Trans.Log.LastDateFoundOnTheMaxdateConnection\" )\n                      + r1 );\n                  }\n                  endDate.setTime( (long) ( maxvalue.getTime() + ( transMeta.getMaxDateOffset() * 1000 ) ) );\n                }\n              } else {\n                if ( log.isDetailed() ) {\n                  log.logDetailed( BaseMessages.getString( PKG, \"Trans.Log.NoLastDateFoundOnTheMaxdateConnection\" ) );\n                }\n              }\n            } catch ( KettleException e ) {\n              throw new KettleTransException( BaseMessages.getString( PKG, \"Trans.Exception.ErrorConnectingToDatabase\",\n                \"\" + transMeta.getMaxDateConnection() ), e );\n            } finally {\n              maxdb.close();\n            }\n          } else {\n            throw new KettleTransException( BaseMessages.getString( PKG,\n              \"Trans.Exception.MaximumDateConnectionCouldNotBeFound\", \"\" + transMeta.getMaxDateConnection() ) );\n          }\n        }\n\n        // Determine the last date of all dependend tables...\n        // Get the maximum in depdate...\n        if ( transMeta.nrDependencies() > 0 ) {\n          if ( log.isDetailed() ) {\n            log.logDetailed( BaseMessages.getString( PKG, \"Trans.Log.CheckingForMaxDependencyDate\" ) );\n          }\n          //\n          // Maybe one of the tables where this transformation is dependent on has changed?","sourceCodeStart":2324,"sourceCodeEnd":2360,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/Trans.java#L2324-L2360","documentation":"When the transformation defines a 'max date' connection used to determine the last date of dependent tables, Trans opens that connection and reads the max date. If connecting or querying the maxdate connection throws a KettleException, it is wrapped in KettleTransException with Trans.Exception.ErrorConnectingToDatabase, including the connection name and the underlying cause.","triggerScenarios":"transMeta.getMaxDateConnection() is set and the attempt to open/query the maxdate Database (maxdb) during init() throws a KettleException (bad connection settings, DB down, wrong credentials, invalid max date SQL/table).","commonSituations":"Max date connection pointing to a stopped/unreachable database; wrong username/password; firewall blocking the DB port; the max date lookup table/field missing or renamed.","solutions":["Check the cause stack trace for the actual JDBC error","Verify the max date connection settings (host, port, DB, credentials) in the transformation","Test the connection with the Database connection 'Test' button / connect manually","Confirm the max date table and field exist and the max date SQL is valid"],"exampleFix":"// before: connection config with wrong host\nDatabaseMeta maxDateConn = new DatabaseMeta(\"log\", \"POSTGRESQL\", \"Native\", \"user\", \"pw\", \"5432\".isEmpty() ? \"localhost\" : \"dbhost-wrong\", \"logs\", null);\n// after: corrected host and verified\nDatabaseMeta maxDateConn = new DatabaseMeta(\"log\", \"POSTGRESQL\", \"Native\", \"user\", \"pw\", \"5432\", \"dbhost\", \"logs\");","handlingStrategy":"validation","validationCode":"DatabaseMeta maxDateConn = transMeta.getMaxDateConnection();\nif (maxDateConn != null) {\n  try (java.sql.Connection c = maxDateConn.getConnection(null)) {\n    if (!c.isValid(5)) throw new IllegalStateException(\"Max date connection invalid\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  trans.execute(args);\n} catch (KettleTransException e) {\n  if (e.getMessage().contains(\"ErrorConnectingToDatabase\")) {\n    log.error(\"Max date connection failed: \" + e.getCause().getMessage());\n    // alert ops / retry after DB recovery\n  } else throw e;\n}","preventionTips":["Test the max date connection in Spoon before scheduling","Verify DB host/port/credentials and firewall rules","Ensure the max date lookup table/field exist","Add a pre-run connectivity health check"],"tags":["kettle","database","connection","maxdate"],"backgroundTag":"connection-refused","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"}