ToolJet/ToolJet · error · QueryError

Connection test failed

Error message

Connection test failed

What it means

Catch-all in ibmdb testConnection: wraps any failure during openConnection or the `SELECT 1 FROM SYSIBM.SYSDUMMY1` probe as a QueryError titled 'Connection test failed', forwarding err.message plus sqlcode/state. Used by the datasource 'Test Connection' button.

Source

Thrown at plugins/packages/ibmdb/lib/index.ts:41

      return { status: 'ok', data: rows };
    } catch (err: any) {
      throw new QueryError('Query could not be completed', err.message || 'An unknown error occurred', {
        sqlcode: err.sqlcode ?? null,
        state: err.state ?? null,
      });
    } finally {
      if (conn) await this.safeClose(conn);
    }
  }

  async testConnection(sourceOptions: SourceOptions): Promise<ConnectionTestResult> {
    let conn: any;
    try {
      conn = await this.openConnection(sourceOptions);
      await this.executeQuery(conn, 'SELECT 1 FROM SYSIBM.SYSDUMMY1');
      return { status: 'ok' };
    } catch (err: any) {
      throw new QueryError('Connection test failed', err.message || 'An unknown error occurred', {
        sqlcode: err.sqlcode ?? null,
        state: err.state ?? null,
      });
    } finally {
      if (conn) await this.safeClose(conn);
    }
  }

  private buildConnectionString(sourceOptions: SourceOptions): string {
    const { host, port, database, username, password } = sourceOptions;
    const parts: string[] = [
      `HOSTNAME=${host}`,
      `PORT=${port || 50000}`,
      `PROTOCOL=TCPIP`,
      `UID=${username}`,
      `PWD=${password || ''}`,
    ];
    // DATABASE is optional — DB2 z/OS does not require it; DB2 LUW typically does

View on GitHub (pinned to 20602a8e10)

Solutions

  1. Verify host, port, database, username, password in sourceOptions.
  2. Check the forwarded err.message / sqlcode for the DB2 reason code (e.g. SQL30081N for transport).
  3. Confirm network reachability from the tool host to the Db2 port.
  4. Ensure the driver native dependencies are installed for the runtime platform.
Defensive patterns

Strategy: try-catch

Validate before calling

for (const k of ['host','port','database','username','password']) {
  if (!sourceOptions[k]) throw new Error(`${k} is required`);
}
if (!/^[1-9][0-9]{0,4}$/.test(String(sourceOptions.port))) throw new Error('invalid port');

Type guard

function isQueryError(e): e is QueryError { return e?.name === 'QueryError' || /Connection test failed/.test(e?.message ?? ''); }

Try / catch

try { result = await plugin.testConnection(sourceOptions); }
catch (e) {
  if (isQueryError(e)) showFormError(`DB2: sqlcode ${e.data?.sqlcode} - ${e.message}`);
  throw e;
}

Prevention

When it happens

Trigger: Wrong host/port/database/credentials in buildConnectionString, IBM i Db2 not reachable, user lacks CONNECT authority, or the driver failed to load/bind (idb-connector native module issue).

Common situations: Typo in host or database name, wrong credentials, firewall between the tool and Db2, or the odbc/idb-connector PASE library missing on the host.

Related errors


AI-assisted analysis of ToolJet/ToolJet@20602a8e10 (2026-08-13). Data as JSON: /api/errors/3584926e98b2054d. Report an issue: GitHub.