{"record":{"id":"50b5a223d5a3d4df","repo":"pentaho/pentaho-kettle","slug":"no-valid-database-connection-defined","errorCode":null,"errorMessage":"No valid database connection defined!","messagePattern":"No valid database connection defined!","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":498,"sourceCode":"    anotherDb.copy = this.opened;\n  }\n\n  /**\n   * Open the database connection. The algorithm is:\n   * <ol>\n   * <li>If <code>databaseMeta.getAccessType()</code> returns\n   * <code>DatabaseMeta.TYPE_ACCESS_JNDI</code>, then the connection's datasource is looked up in JNDI </li>\n   * <li>If <code>databaseMeta.isUsingConnectionPool()</code>, then the connection's datasource is looked up in the\n   * pool</li>\n   * <li>otherwise, the connection is established via {@linkplain java.sql.DriverManager}</li>\n   * </ol>\n   *\n   * @param partitionId the partition ID in the cluster to connect to.\n   * @throws KettleDatabaseException if something went wrong.\n   */\n  public void normalConnect( String partitionId ) throws KettleDatabaseException {\n    if ( databaseMeta == null ) {\n      throw new KettleDatabaseException( \"No valid database connection defined!\" );\n    }\n\n    try {\n      if ( databaseMeta.getAccessType() == DatabaseMeta.TYPE_ACCESS_JNDI ) {\n        log.logDetailed( \"Acquiring JNDI connection for database [\" + databaseMeta.getName() + \"]...\" );\n        long startJndi = System.currentTimeMillis();\n        this.connection = getDataSource( partitionId ).getConnection();\n        log.logDetailed( \"JNDI connection acquired for database [\" + databaseMeta.getName() + \"] in \" + ( System.currentTimeMillis() - startJndi ) + \" ms\" );\n      } else if ( databaseMeta.isUsingConnectionPool() ) {\n        log.logDetailed( \"Acquiring pooled connection for database [\" + databaseMeta.getName() + \"]...\" );\n        long startPool = System.currentTimeMillis();\n        this.connection = getDataSource( partitionId ).getConnection();\n        log.logDetailed( \"Pooled connection acquired for database [\" + databaseMeta.getName() + \"] in \" + ( System.currentTimeMillis() - startPool ) + \" ms\" );\n        if ( getConnection().getAutoCommit() != isAutoCommit() ) {\n          setAutoCommit( isAutoCommit() );\n        }\n      } else {\n        // using non-jndi and non-pooled connection -- just a simple JDBC","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L480-L516","documentation":"Database.normalConnect throws KettleDatabaseException(\"No valid database connection defined!\") when the Database instance has no databaseMeta set. A Database object cannot open any connection without its DatabaseMeta configuration object.","triggerScenarios":"Calling connect() or normalConnect(partitionId) on a Database created without a DatabaseMeta, or after databaseMeta was set to null; also shareConnectionWith/test paths that operate on an unconfigured Database.","commonSituations":"Constructing new Database() with the no-arg constructor and forgetting setDatabaseMeta(); deserialization/transformation metadata loading that left databaseMeta null; refactorings that lost the metadata assignment before connect.","solutions":["Set a DatabaseMeta before connecting: database.setDatabaseMeta(dbMeta) or use the Database(DatabaseMeta) constructor","Verify the metadata came from a valid repository/shared connection definition","Guard with a null check on getDatabaseMeta() before calling connect()"],"exampleFix":"// before\nDatabase db = new Database( loggingObject, null );\ndb.connect();\n\n// after\nDatabase db = new Database( loggingObject, databaseMeta );\nif ( db.getDatabaseMeta() != null ) {\n  db.connect();\n}","handlingStrategy":"validation","validationCode":"if ( databaseMeta == null ) {\n  throw new IllegalArgumentException( \"DatabaseMeta must be set before connect()\" );\n}","typeGuard":"if ( database == null || database.getDatabaseMeta() == null ) {\n  return; // not configured; skip connection attempt\n}","tryCatchPattern":"try {\n  db.connect();\n} catch ( KettleDatabaseException e ) {\n  log.error( \"Connection not configured: \" + e.getMessage() );\n}","preventionTips":["Always construct Database with a DatabaseMeta via constructor or setDatabaseMeta","Validate metadata loading (repository/shared XML) before instantiating Database","Null-check getDatabaseMeta() in helper code that wraps connect()"],"tags":["null-configuration","database","kettle-database-exception"],"backgroundTag":"missing-required-config-field","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"}