{"record":{"id":"e1f1458bcb49a21f","repo":"risingwavelabs/risingwave","slug":"no-result-returned-when-querying-sql-server-max-mi","errorCode":null,"errorMessage":"No result returned when querying SQL Server max/min LSN","messagePattern":"No result returned when querying SQL Server max/min LSN","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/connector/src/source/cdc/enumerator/mod.rs","lineNumber":319,"sourceCode":"        config.host(hostname);\n        config.port(port);\n        config.database(database);\n        config.authentication(tiberius::AuthMethod::sql_server(username, password));\n        config.trust_cert();\n\n        let mut client = SqlServerClient::new_with_config(config).await?;\n        let row = client\n            .inner_client\n            .simple_query(\n                \"SELECT \\\n                    sys.fn_cdc_get_max_lsn() AS max_lsn, \\\n                    (SELECT MIN(sys.fn_cdc_get_min_lsn(capture_instance)) FROM cdc.change_tables) AS min_lsn\"\n                    .to_owned(),\n            )\n            .await?\n            .into_row()\n            .await?\n            .ok_or_else(|| anyhow!(\"No result returned when querying SQL Server max/min LSN\"))?;\n\n        let lsn_bytes_to_hex = |bytes: &[u8]| -> ConnectorResult<String> {\n            if bytes.len() != 10 {\n                return Err(anyhow!(\n                    \"SQL Server LSN should be 10 bytes, got {} bytes\",\n                    bytes.len()\n                )\n                .into());\n            }\n            let mut hex_string = String::with_capacity(22);\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(':');","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/source/cdc/enumerator/mod.rs#L301-L337","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Enable CDC on the SQL Server database (`EXEC sys.sp_cdc_enable_db`) and on the source table (`sys.sp_cdc_enable_table`)","Verify you are connected to the same database.name configured on the CDC source","Check `SELECT name, is_cdc_enabled FROM sys.databases` and `sys.tables.is_tracked_by_cdc`","Ensure the SQL Server Agent is running so capture jobs populate CDC metadata"],"exampleFix":"// on SQL Server, before running the RW CDC source\nEXEC sys.sp_cdc_enable_db;\nEXEC sys.sp_cdc_enable_table\n  @source_schema = N'dbo', @source_name = N'my_table',\n  @role_name = NULL;","handlingStrategy":"validation","validationCode":"// Before relying on the CDC source, verify CDC is enabled:\n// SELECT name, is_cdc_enabled FROM sys.databases WHERE name = @db;\n// SELECT t.name FROM sys.tables t WHERE t.is_tracked_by_cdc = 1;","typeGuard":null,"tryCatchPattern":"match res {\n    Ok(Some((min, max))) => track_lsns(min, max),\n    Ok(None) | Err(e) if e.to_string().contains(\"No result returned\") => {\n        warn!(\"CDC not enabled on SQL Server database: {}\", e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Enable CDC at the database and table level before creating the source","Verify `sys.databases.is_cdc_enabled` and `sys.tables.is_tracked_by_cdc` during setup","Ensure the SQL Server Agent is running"],"tags":["cdc","sql-server","database","empty-result"],"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-23T08:17:48.524Z"}