{"record":{"id":"8c1ab253324a6bca","repo":"pentaho/pentaho-kettle","slug":"database-connection-not-found","errorCode":null,"errorMessage":"Database connection not found: ","messagePattern":"Database connection not found: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":490,"sourceCode":"    } else {\n      throw new RuntimeException( \"The function call isWorkingDay requires 1 argument.\" );\n    }\n  }\n\n  @SuppressWarnings( \"unused\" )\n  public static Object fireToDB( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n\n    Object oRC = new Object();\n    if ( ArgList.length == 2 ) {\n      try {\n        Object scmO = actualObject.get( \"_step_\" );\n        Script scm = (Script) scmO;\n        String strDBName = (String) ArgList[0];\n        String strSQL = (String) ArgList[1];\n        DatabaseMeta ci = DatabaseMeta.findDatabase( scm.getTransMeta().getDatabases(), strDBName );\n        if ( ci == null ) {\n          throw new RuntimeException( \"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":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L472-L508","documentation":"fireToDB(dbName, sql) executes SQL against a named transformation database connection. It looks up the connection by name with DatabaseMeta.findDatabase on the transformation's database metadata; if no connection with that name exists, it throws this RuntimeException naming the missing connection.","triggerScenarios":"Calling fireToDB('MyConn', 'select ...') where 'MyConn' is not defined as a shared database connection on the transformation's metadata.","commonSituations":"Typo in the connection name; connection defined in a different environment or repository but not shared to this transformation; renaming a connection without updating scripts; jobs run outside Spoon where shared connections were not exported.","solutions":["Define a database connection with exactly the name passed as the first argument and share it on the transformation.","Check spelling/case of the connection name in the script against the transformation's connections list.","Log the available connection names (scm.getTransMeta().getDatabases()) to confirm what exists."],"exampleFix":"// before\nfireToDB('MyCon', 'DELETE FROM logs');\n// after\nfireToDB('MyConn', 'DELETE FROM logs'); // matches the shared connection name","handlingStrategy":"try-catch","validationCode":"// in script: verify connection name exists\nvar conns = _step_.getTransMeta().getDatabases();\nfor (var i = 0; i < conns.length; i++) { if (conns[i].getName() == 'MyConn') { /* ok */ } }","typeGuard":null,"tryCatchPattern":"try { fireToDB('MyConn', sql); } catch (e) { if (String(e).indexOf('Database connection not found') >= 0) { /* fix connection definition/name */ } else { throw e; } }","preventionTips":["Share the database connection on the transformation and keep its name in sync with scripts.","Avoid hardcoding connection names; define them once per environment.","Test the connection in the Database Connection dialog first."],"tags":["database","script-step","configuration"],"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"}