{"record":{"id":"9a800634089b19bd","repo":"apache/seatunnel","slug":"no-result-returned-after-running-query-rowcount-9a8006","errorCode":null,"errorMessage":"No result returned after running query [${rowCountQuery}]","messagePattern":"No result returned after running query \\[(.+?)\\]","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlServerDialect.java","lineNumber":220,"sourceCode":"            TablePath tablePath = table.getTablePath();\n            try (Statement stmt = connection.createStatement()) {\n                if (StringUtils.isNotBlank(tablePath.getDatabaseName())) {\n                    String useDatabaseStatement =\n                            String.format(\n                                    \"USE %s;\",\n                                    quoteDatabaseIdentifier(tablePath.getDatabaseName()));\n                    log.info(\"Split Chunk, approximateRowCntStatement: {}\", useDatabaseStatement);\n                    stmt.execute(useDatabaseStatement);\n                }\n                String rowCountQuery =\n                        String.format(\n                                \"SELECT Total_Rows = SUM(st.row_count) FROM sys\"\n                                        + \".dm_db_partition_stats st WHERE object_name(object_id) = '%s' AND index_id < 2;\",\n                                tablePath.getTableName());\n                log.info(\"Split Chunk, approximateRowCntStatement: {}\", rowCountQuery);\n                try (ResultSet rs = stmt.executeQuery(rowCountQuery)) {\n                    if (!rs.next()) {\n                        throw new SQLException(\n                                String.format(\n                                        \"No result returned after running query [%s]\",\n                                        rowCountQuery));\n                    }\n                    return rs.getLong(1);\n                }\n            }\n        }\n        return SQLUtils.countForSubquery(connection, table.getQuery());\n    }\n\n    @Override\n    public Object queryNextChunkMax(\n            Connection connection,\n            JdbcSourceTable table,\n            String columnName,\n            int chunkSize,\n            Object includedLowerBound)","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlServerDialect.java#L202-L238","documentation":"Thrown by SqlServerDialect.approximateRowCntStatement when the row-count estimation query against sys.dm_db_partition_stats returns no rows. The splitter needs a row count to compute chunk boundaries, so an empty result is treated as a hard failure.","triggerScenarios":"Calling approximateRowCntStatement for a table that does not exist, is not visible to the current user (missing VIEW DATABASE STATE / VIEW DEFINITION permissions), or has no rows in sys.dm_db_partition_stats (e.g. table name case/schema mismatch via object_name(object_id)).","commonSituations":"Splitting a table whose name differs in case or schema from what was passed; connecting with a login lacking catalog view permissions; querying a temp or recently created empty table on certain SQL Server editions.","solutions":["Verify the table exists and its name/schema matches exactly what was passed to the connector","Grant the SQL Server user the VIEW DATABASE STATE permission so dm_db_partition_stats returns rows","Use an account with db_owner or sysadmin rights for schema-split reads","Check SQL Server edition: some editions/services expose DMVs differently; verify with a manual SELECT against sys.dm_db_partition_stats"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before splitting, verify the table is visible and countable\nSELECT SUM(st.row_count) FROM sys.dm_db_partition_stats st\nWHERE object_name(object_id) = 'MyTable' AND index_id < 2;","typeGuard":null,"tryCatchPattern":"try {\n    source.open();\n} catch (SQLException e) {\n    if (e.getMessage().startsWith(\"No result returned after running query\")) {\n        // fall back to a non-approximate splitter or fix permissions\n    }\n}","preventionTips":["Grant VIEW DATABASE STATE to the connector user","Ensure exact table name/schema case matches","Confirm table exists before starting split reads","Test with the same SQL Server user the connector uses"],"tags":["jdbc","sqlserver","split-reading","empty-result"],"backgroundTag":"empty-result-set","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}