metricsign
Start free
Low severityexecutionSnowflake

Power BI Refresh Error:
252006

What does this error mean?

An operation was attempted on a cursor object that has already been closed. Once cursor.close() is called, the cursor cannot be used for further query execution or result fetching.

Common causes

  • 1Calling cursor.execute() or cursor.fetchall() after cursor.close() has been called
  • 2Using a cursor after exiting a context manager (with conn.cursor() as cursor) that closes it automatically
  • 3Cursor was closed due to connection.close() being called while the cursor was still in scope
  • 4Reusing a cursor object stored in a module-level variable after the connection was recycled
  • 5Multi-threaded code where one thread closes the cursor while another is still using it

How to fix it

  1. 1Create a new cursor for each query: use cursor = conn.cursor() before each operation.
  2. 2Use context managers and do all cursor operations inside the with block.
  3. 3Do not store cursor objects at module level — always create them from the active connection.
  4. 4In multi-threaded code, create separate cursors per thread or use a thread-safe connection pool.
  5. 5If using connection.close() as a cleanup step, ensure all cursors are finished before closing.

Frequently asked questions

Should I reuse a cursor across multiple queries?

You can, but be cautious — always fetch all results before executing the next query on the same cursor. For concurrent operations, use separate cursors.

Does closing the connection automatically close all cursors?

Yes — closing the connection invalidates all cursors derived from it. Always complete cursor operations before closing the connection.

Official documentation: https://github.com/snowflakedb/snowflake-connector-python/blob/main/src/snowflake/connector/errorcode.py

Other execution errors