{"record":{"id":"e603e448bd9e9fe7","repo":"pentaho/pentaho-kettle","slug":"database-connection-not-found-scriptvaluesaddedfunctions","errorCode":null,"errorMessage":"Database connection not found: ","messagePattern":"Database connection not found: ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":508,"sourceCode":"    } else {\n      throw Context.reportRuntimeError( \"The function call isWorkingDay requires 1 argument.\" );\n    }\n  }\n\n  @SuppressWarnings( \"unused\" )\n  public static Object fireToDB( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n\n    Object oRC = new Object();\n    if ( ArgList.length == 2 ) {\n      try {\n        Object scmO = actualObject.get( \"_step_\", actualObject );\n        ScriptValuesMod scm = (ScriptValuesMod) Context.jsToJava( scmO, ScriptValuesMod.class );\n        String strDBName = Context.toString( ArgList[0] );\n        String strSQL = Context.toString( ArgList[1] );\n        DatabaseMeta ci = DatabaseMeta.findDatabase( scm.getTransMeta().getDatabases(), strDBName );\n        if ( ci == null ) {\n          throw Context.reportRuntimeError( \"Database connection not found: \" + strDBName );\n        }\n        ci.shareVariablesWith( scm );\n\n        Database db = new Database( scm, ci );\n        db.setQueryLimit( 0 );\n        try {\n          if ( scm.getTransMeta().isUsingUniqueConnections() ) {\n            synchronized ( scm.getTrans() ) {\n              db.connect( scm.getTrans().getTransactionId(), scm.getPartitionID() );\n            }\n          } else {\n            db.connect( scm.getPartitionID() );\n          }\n\n          ResultSet rs = db.openQuery( strSQL );\n          ResultSetMetaData resultSetMetaData = rs.getMetaData();\n          int columnCount = resultSetMetaData.getColumnCount();\n          if ( rs != null ) {","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L490-L526","documentation":"fireToDB executes a SQL statement against a named database connection from within a Modified Java Script Value step. It resolves the connection by name via DatabaseMeta.findDatabase over the transformation's database connections; if no connection matches the given name it throws this error naming the connection.","triggerScenarios":"fireToDB('wrongName', sql) where strDBName does not match any shared database connection defined in the transformation (DatabaseMeta.findDatabase returns null).","commonSituations":"Typo or case mismatch in the connection name; the connection was defined in another transformation/job and never shared into this one; the connection was deleted or renamed after the script was written; running the transformation on a server/environment lacking that connection metadata.","solutions":["Correct the first argument to exactly match a database connection name defined in the transformation (Transformations > Database connections).","Share the needed database connection into the transformation via a shared.xml / reference it so getDatabases() contains it.","Check for case/whitespace differences between the script string and the connection name.","Verify the environment you deploy to (e.g. Carte/Kitchen) has the same connection metadata."],"exampleFix":"// before\nfireToDB('MyDb ', 'SELECT 1');  // trailing space, connection 'MyDB'\n// after\nfireToDB('MyDB', 'SELECT 1');","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  fireToDB('MyDB', 'INSERT INTO log(msg) VALUES (?)');\n} catch (e) {\n  if (String(e).indexOf('Database connection not found') >= 0) {\n    writeToLog('Error', 'Check connection name in transformation settings: ' + e);\n    throw e;\n  }\n  throw e;\n}","preventionTips":["Copy connection names directly from the transformation's Database connections dialog.","Use shared connections so every environment resolves the same metadata.","Avoid hardcoded connection strings in scripts; centralize them in constants.","Validate connections in a pre-step or job before running script-based SQL."],"tags":["javascript","database","connection","pdi-kettle"],"backgroundTag":"resource-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"}