{"record":{"id":"6b57c2fde59e3a31","repo":"risingwavelabs/risingwave","slug":"none-is-returned-by-select-sys-fn-cdc-get-max-lsn","errorCode":null,"errorMessage":"None is returned by `SELECT sys.fn_cdc_get_max_lsn()`, please ensure Sql Server Agent is running.","messagePattern":"None is returned by `SELECT sys\\.fn_cdc_get_max_lsn\\(\\)`, please ensure Sql Server Agent is running\\.","errorType":"exception","errorClass":"ConnectorError","httpStatus":null,"severity":"error","filePath":"src/connector/src/source/cdc/external/sql_server.rs","lineNumber":258,"sourceCode":"                assert_eq!(\n                    bytes.len(),\n                    10,\n                    \"sys.fn_cdc_get_max_lsn() should return a 10 bytes array.\"\n                );\n                for byte in &bytes[0..4] {\n                    hex_string.push_str(&format!(\"{:02x}\", byte));\n                }\n                hex_string.push(':');\n                for byte in &bytes[4..8] {\n                    hex_string.push_str(&format!(\"{:02x}\", byte));\n                }\n                hex_string.push(':');\n                for byte in &bytes[8..10] {\n                    hex_string.push_str(&format!(\"{:02x}\", byte));\n                }\n                hex_string\n            }\n            None => bail!(\n                \"None is returned by `SELECT sys.fn_cdc_get_max_lsn()`, please ensure Sql Server Agent is running.\"\n            ),\n        };\n\n        tracing::debug!(\"current max_lsn: {}\", max_lsn);\n\n        Ok(CdcOffset::SqlServer(SqlServerOffset {\n            change_lsn: max_lsn,\n            commit_lsn: MAX_COMMIT_LSN.into(),\n        }))\n    }\n\n    fn snapshot_read(\n        &self,\n        table_name: SchemaTableName,\n        start_pk: Option<OwnedRow>,\n        primary_keys: Vec<String>,\n        limit: u32,","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/source/cdc/external/sql_server.rs#L240-L276","documentation":"The query `SELECT sys.fn_cdc_get_max_lsn()` returned a row but the cell was NULL, i.e. CDC capture jobs have never produced a max LSN. `fn_cdc_get_max_lsn` returns NULL until the SQL Server Agent capture job has populated change tables, so this error points at an environment/agent problem rather than code.","triggerScenarios":"CDC enabled on table metadata but SQL Server Agent not running (common on containers, Linux installs, or localdb), or capture job stopped/failed right after enabling CDC, when `current_cdc_offset` is called to compute the start offset.","commonSituations":"Docker mssql image without Agent started; Agent license/edition limitations; capture job failing due to missing sysadmin; freshly enabled CDC where no transaction has been captured yet.","solutions":["Start SQL Server Agent: `EXEC master.dbo.xp_servicecontrol N'START', N'SQLServerAGENT'` or start the service on the host/container.","Check that the CDC capture and cleanup jobs exist and are running (msdb.dbo.cdc_jobs; sqlagent job history).","Confirm sys.fn_cdc_is_cdc_enabled(DB_ID()) and sys.fn_cdc_has_work_completed return expected values; generate a small change to trigger capture.","If Agent cannot run (e.g. some editions), consider CDC alternatives (CT/Debezium setup) — RisingWave requires a resolvable max LSN."],"exampleFix":"// before\nNone => bail!(\"None is returned by `SELECT sys.fn_cdc_get_max_lsn()`, please ensure Sql Server Agent is running.\"),\n// after (user-side check before starting the source)\n-- SELECT sys.fn_cdc_get_max_lsn(); -- must be non-NULL before creating the CDC source","handlingStrategy":"validation","validationCode":"-- Verify Agent + capture job before starting the source:\nSELECT sys.fn_cdc_get_max_lsn(); -- must be non-NULL\nSELECT name, enabled FROM msdb.dbo.cdc_jobs WHERE database_id = DB_ID();","typeGuard":null,"tryCatchPattern":"match row.try_get::<&[u8], usize>(0) {\n    Ok(Some(bytes)) => bytes,\n    Ok(None) | Err(_) => return Err(anyhow!(\"max LSN is NULL; start SQL Server Agent and enable CDC\")),\n}","preventionTips":["Ensure SQL Server Agent starts automatically (container: enable the agent entrypoint).","Check cdc_jobs and SQL Agent job history after enabling CDC.","Generate and capture a test transaction before attaching RisingWave."],"tags":["cdc","sql-server","lsn","sql-server-agent"],"backgroundTag":"empty-result-set","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}