apache/beam · error · IllegalArgumentException

SQL Server does not support connectionInitSql.

Error message

SQL Server does not support connectionInitSql.

What it means

Thrown by WriteToSqlServerSchemaTransformProvider.from() when connectionInitSql is supplied. The SQL Server write path does not support connection initialization SQL; the provider fails fast and then explicitly resets the list to empty before building a SqlServerWriteSchemaTransform.

Source

Thrown at sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/providers/WriteToSqlServerSchemaTransformProvider.java:73

  }

  @Override
  public @UnknownKeyFor @NonNull @Initialized SchemaTransform from(
      JdbcWriteSchemaTransformConfiguration configuration) {
    String jdbcType = configuration.getJdbcType();
    if (jdbcType != null && !jdbcType.isEmpty() && !jdbcType.equals(jdbcType())) {
      LOG.warn(
          "Wrong JDBC type. Expected '{}' but got '{}'. Overriding with '{}'.",
          jdbcType(),
          jdbcType,
          jdbcType());
      configuration = configuration.toBuilder().setJdbcType(jdbcType()).build();
    }

    List<@org.checkerframework.checker.nullness.qual.Nullable String> connectionInitSql =
        configuration.getConnectionInitSql();
    if (connectionInitSql != null && !connectionInitSql.isEmpty()) {
      throw new IllegalArgumentException("SQL Server does not support connectionInitSql.");
    }

    // Override "connectionInitSql" for sqlserver
    configuration = configuration.toBuilder().setConnectionInitSql(Collections.emptyList()).build();
    return new SqlServerWriteSchemaTransform(configuration);
  }

  public static class SqlServerWriteSchemaTransform extends JdbcWriteSchemaTransform {
    public SqlServerWriteSchemaTransform(JdbcWriteSchemaTransformConfiguration config) {
      super(config, MSSQL);
      config.validate(MSSQL);
    }
  }
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Remove connectionInitSql entries from the SQL Server write configuration
  2. Apply required session settings via SQL Server database/user defaults or within the write statements
  3. Gate connectionInitSql to dialects that support it in your config templating

Example fix

// before
builder().setConnectionInitSql(ImmutableList.of("SET NOCOUNT ON"))
// after
builder() // use server/database defaults instead
Defensive patterns

Strategy: validation

Validate before calling

if (connectionInitSql != null && !connectionInitSql.isEmpty()) {
  throw new IllegalArgumentException("SQL Server write does not support connectionInitSql; remove it from the config");
}

Prevention

When it happens

Trigger: Calling WriteToSqlServerSchemaTransformProvider.from()/builder with a non-empty connectionInitSql list.

Common situations: Shared JDBC configuration reused across MySQL and SQL Server writes; templated configs always emitting connectionInitSql; migrations from MySQL to SQL Server without option cleanup.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/8a2fdf8bfebb30fe. Report an issue: GitHub.