MetricSign
EN|NLRequest Access
Medium severityquery

Power BI Refresh Error:
INVALID_CURSOR_OPERATION

What does this error mean?

A cursor operation (FETCH, CLOSE, MOVE) was attempted on a cursor that is not open, has already been closed, or does not exist in the current session.

Common causes

  • 1Attempting to FETCH from a cursor after it was already CLOSEd
  • 2Cursor declared in one session or connection being referenced in another
  • 3SQL warehouse session timeout closing the cursor before the fetch loop completed
  • 4Application code not handling cursor lifecycle correctly across retries
  • 5Using cursor operations in a SQL warehouse that does not support session-persistent cursors

How to fix it

  1. 1Ensure the cursor lifecycle (DECLARE → OPEN → FETCH → CLOSE) is completed within a single session
  2. 2Add error handling to detect and re-open cursors that were closed due to a session timeout
  3. 3Increase the SQL warehouse idle timeout if cursors are timing out mid-fetch
  4. 4For large result sets, consider using the Databricks statement execution REST API with pagination instead of cursors
  5. 5Check that retry logic in application code re-declares and re-opens the cursor on retry rather than resuming from a closed state

Frequently asked questions

Is cursor-based pagination recommended for SQL warehouses?

For large result sets, the Databricks statement execution API with `nextChunkIndex` pagination is more reliable than SQL cursor operations, which depend on session continuity.

Other query errors