risingwavelabs/risingwave · error

No result returned when querying SQL Server max/min LSN

Error message

No result returned when querying SQL Server max/min LSN

What it means

`query_sql_server_lsns` issues a query selecting MAX/MIN LSN from `cdc.change_tables`; if `into_row()` yields no row, this error is thrown. It means SQL Server connected and executed the query but returned an empty result set.

Solutions

  1. Enable CDC on the SQL Server database (`EXEC sys.sp_cdc_enable_db`) and on the source table (`sys.sp_cdc_enable_table`)
  2. Verify you are connected to the same database.name configured on the CDC source
  3. Check `SELECT name, is_cdc_enabled FROM sys.databases` and `sys.tables.is_tracked_by_cdc`
  4. Ensure the SQL Server Agent is running so capture jobs populate CDC metadata

Example fix

// on SQL Server, before running the RW CDC source
EXEC sys.sp_cdc_enable_db;
EXEC sys.sp_cdc_enable_table
  @source_schema = N'dbo', @source_name = N'my_table',
  @role_name = NULL;
Defensive patterns

Strategy: validation

Validate before calling

// Before relying on the CDC source, verify CDC is enabled:
// SELECT name, is_cdc_enabled FROM sys.databases WHERE name = @db;
// SELECT t.name FROM sys.tables t WHERE t.is_tracked_by_cdc = 1;

Try / catch

match res {
    Ok(Some((min, max))) => track_lsns(min, max),
    Ok(None) | Err(e) if e.to_string().contains("No result returned") => {
        warn!("CDC not enabled on SQL Server database: {}", e);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Executing the LSN query against a database where `cdc.change_tables` is empty — i.e. no table in the database has CDC capture instances enabled.

Common situations: CDC not enabled on the database or on the source table (`sys.sp_cdc_enable_db` / `sys.sp_cdc_enable_table` never run); querying the wrong database; SQL Server Agent not running so capture tables exist but... typically CDC was never enabled.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/e1f1458bcb49a21f. Report an issue: GitHub.

Appendix: source

Thrown at src/connector/src/source/cdc/enumerator/mod.rs:319

        config.host(hostname);
        config.port(port);
        config.database(database);
        config.authentication(tiberius::AuthMethod::sql_server(username, password));
        config.trust_cert();

        let mut client = SqlServerClient::new_with_config(config).await?;
        let row = client
            .inner_client
            .simple_query(
                "SELECT \
                    sys.fn_cdc_get_max_lsn() AS max_lsn, \
                    (SELECT MIN(sys.fn_cdc_get_min_lsn(capture_instance)) FROM cdc.change_tables) AS min_lsn"
                    .to_owned(),
            )
            .await?
            .into_row()
            .await?
            .ok_or_else(|| anyhow!("No result returned when querying SQL Server max/min LSN"))?;

        let lsn_bytes_to_hex = |bytes: &[u8]| -> ConnectorResult<String> {
            if bytes.len() != 10 {
                return Err(anyhow!(
                    "SQL Server LSN should be 10 bytes, got {} bytes",
                    bytes.len()
                )
                .into());
            }
            let mut hex_string = String::with_capacity(22);
            for byte in &bytes[0..4] {
                hex_string.push_str(&format!("{:02x}", byte));
            }
            hex_string.push(':');
            for byte in &bytes[4..8] {
                hex_string.push_str(&format!("{:02x}", byte));
            }
            hex_string.push(':');

View on GitHub (pinned to 6469eb736d)