{"record":{"id":"8150092e96bcb14a","repo":"pentaho/pentaho-kettle","slug":"jobsql-errorrunningsqlfromfile","errorCode":"JobSQL.ErrorRunningSQLfromFile","errorMessage":"JobSQL.ErrorRunningSQLfromFile","messagePattern":"JobSQL\\.ErrorRunningSQLfromFile","errorType":"error_code","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/job/entries/sql/JobEntrySQL.java","lineNumber":304,"sourceCode":"\n      try ( InputStream inputStream = KettleVFS.getInputStream( sqlFile ) ) {\n        InputStreamReader bufferedStream = new InputStreamReader( new BufferedInputStream( inputStream, 500 ) );\n\n        BufferedReader buff = new BufferedReader( bufferedStream );\n        String sLine;\n        StringBuilder sqlBuilder = new StringBuilder( Const.CR );\n\n        while ( ( sLine = buff.readLine() ) != null ) {\n          if ( Utils.isEmpty( sLine ) ) {\n            sqlBuilder.append( Const.CR );\n          } else {\n            sqlBuilder.append( Const.CR ).append( sLine );\n          }\n        }\n        return sqlBuilder.toString();\n      }\n    } catch ( Exception e ) {\n      throw new KettleDatabaseException( BaseMessages.getString( PKG, \"JobSQL.ErrorRunningSQLfromFile\" ), e );\n    }\n  }\n\n  public boolean evaluates() {\n    return true;\n  }\n\n  public boolean isUnconditional() {\n    return true;\n  }\n\n  public DatabaseMeta[] getUsedDatabaseConnections() {\n    return new DatabaseMeta[] { databaseMeta, };\n  }\n\n  public List<ResourceReference> getResourceDependencies( JobMeta jobMeta ) {\n    List<ResourceReference> references = super.getResourceDependencies( jobMeta );\n    if ( databaseMeta != null ) {","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/job/entries/sql/JobEntrySQL.java#L286-L322","documentation":"KettleDatabaseException with localized message JobSQL.ErrorRunningSQLfromFile thrown by JobEntrySQL.buildSqlFromFile as a catch-all for any Exception while reading the SQL file (after existence checks). It wraps I/O errors, permission problems, and encoding/parse issues encountered while building the SQL text.","triggerScenarios":"Calling buildSqlFromFile when KettleVFS.getFileObject, opening the input stream, or line-by-line reading throws: file locked, no read permission, unsupported filesystem/URI, or IO error mid-read.","commonSituations":"File opened exclusively by another process; service account lacks read permission; file on an unreachable network share; wrong file content/encoding causing reader errors.","solutions":["Check the wrapped cause exception to identify the underlying I/O error.","Verify the service user has read permission on the file and its directory.","Confirm the network share/remote filesystem is reachable from the execution host.","Re-validate the file (not locked, correct encoding) and retry the job."],"exampleFix":"// before\nFile f = new File(path);\nString sql = Files.readString(f.toPath()); // may throw on permission/IO\n// after\nFile f = new File(path);\nif (!f.canRead()) {\n  logError(\"No read permission on SQL file: \" + path);\n}\nString sql = Files.readString(f.toPath());","handlingStrategy":"try-catch","validationCode":"String real = sqlEntry.environmentSubstitute(sqlEntry.getSqlFilename());\nFile f = new File(real);\nif (!f.exists() || !f.canRead()) {\n  throw new KettleException(\"SQL file missing or unreadable: \" + real);\n}\n","typeGuard":null,"tryCatchPattern":"try {\n  result = sqlEntry.execute(prev, 0);\n} catch (KettleDatabaseException e) {\n  logError(\"Error reading SQL file: \" + e.getCause(), e); // cause holds the I/O detail\n}","preventionTips":["Grant the service account read access to SQL files","Check for file locks from editors/AV on execution hosts","Ensure network shares are mounted before job runs","Validate file encoding matches the reader"],"tags":["file-read","pdi","job-entry","sql","io"],"backgroundTag":"file-read-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"}