{"record":{"id":"e9e2650fe3d2bc24","repo":"pentaho/pentaho-kettle","slug":"error-occurred-while-trying-to-retrieve-the-datasource","errorCode":null,"errorMessage":"Error occurred while trying to retrieve the DataSource","messagePattern":"Error occurred while trying to retrieve the DataSource","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":552,"sourceCode":"  }\n\n  public void initializeConnectionDataSource( String partitionId ) throws KettleDatabaseException {\n\n    try {\n      DataSourceProviderInterface dsp = DataSourceProviderFactory.getDataSourceProviderInterface();\n      if ( dsp == null ) {\n        // since DataSourceProviderFactory is initialised with new DatabaseUtil(),\n        // this assignment is correct\n        dsp = new DatabaseUtil();\n      }\n\n      if ( databaseMeta.getAccessType() == DatabaseMeta.TYPE_ACCESS_JNDI ) {\n        this.dataSource = getJNDIDataSource( dsp );\n      } else if ( databaseMeta.isUsingConnectionPool() ) {\n        this.dataSource = getPoolingDataSource( partitionId, dsp );\n      }\n    } catch ( Exception e ) {\n      throw new KettleDatabaseException( \"Error occurred while trying to retrieve the DataSource\", e );\n    }\n  }\n\n  private DataSource getPoolingDataSource( String partitionId, DataSourceProviderInterface dsp ) throws Exception {\n\n    try {\n      return dsp.getPooledDataSourceFromMeta( databaseMeta, DatasourceType.POOLED );\n    } catch ( UnsupportedOperationException e ) {\n      // UnsupportedOperationException is happen at DatabaseUtil doesn't support pooled DS, use legacy routine\n      // NullPointerException is happen when we will try to run the transformation on the remote server but\n      // server does not have such databases, so will using legacy routine as well\n      if ( databaseMeta.isNeedUpdate() && !ConnectionPoolUtil.hasOldConfig( databaseMeta, partitionId ) ) {\n        dsp.invalidateNamedDataSource( ConnectionPoolUtil.getDataSourceName( databaseMeta, partitionId ),\n          DatasourceType.POOLED );\n        databaseMeta.setNeedUpdate( false );\n      }\n      return ConnectionPoolUtil.getDataSource( log, databaseMeta, partitionId );\n    }","sourceCodeStart":534,"sourceCodeEnd":570,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L534-L570","documentation":"initializeConnectionDataSource wraps failures while obtaining a DataSource (JNDI lookup or pooled lookup through the DataSourceProviderInterface) into KettleDatabaseException(\"Error occurred while trying to retrieve the DataSource\", cause). It is thrown when getJNDIDataSource or getPoolingDataSource raises any exception.","triggerScenarios":"Calling getDataSource()/initializeConnectionDataSource when access type is JNDI but the JNDI lookup fails, or when using a connection pool and DataSourceProviderInterface throws (e.g. naming exceptions, unsupported-operation stubs from errors 140/141).","commonSituations":"Misconfigured JNDI name in DatabaseMeta, missing JNDI server/properties file, custom DataSourceProviderInterface throwing, or pooled datasource provisioning failures in the app server.","solutions":["Inspect the cause chain for the underlying JNDI or provider exception","Verify the JNDI datasource name matches one defined in the container (jdbc.properties / context.xml)","If not using JNDI, confirm connection pool settings and that the provider supports pooled lookups","Fall back to Native (JDBC) access type if DataSource retrieval is not required"],"exampleFix":"// before\nDataSource ds = db.getDataSource(); // throws wrapped error\n\n// after\ntry {\n  DataSource ds = db.getDataSource();\n} catch ( KettleDatabaseException e ) {\n  log.error( \"DataSource lookup failed: \" + e.getCause(), e );\n}","handlingStrategy":"try-catch","validationCode":"if ( dbMeta.getAccessType() == DatabaseMeta.TYPE_ACCESS_JNDI ) {\n  // confirm the JNDI name is defined in the container before lookup\n  validateJndiNameExists( dbMeta.getDatabaseName() );\n}","typeGuard":null,"tryCatchPattern":"try {\n  DataSource ds = db.getDataSource();\n} catch ( KettleDatabaseException e ) {\n  log.error( \"DataSource retrieval failed: \" + e.getCause(), e );\n}","preventionTips":["Verify JNDI datasource definitions in the app server before deploying","Only use JNDI/pooled access types inside a container that provides them","Fall back to native JDBC access when no container datasource exists"],"tags":["jndi","datasource","database"],"backgroundTag":"datasource-lookup-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"}