How to fix Error 115 on Windows Server 2025 / Windows 11

Why This Error Happens

Error 115 occurs because SQL Server’s T-SQL syntax does not permit the FOR UPDATE clause to be combined with set operators such as UNION, UNION ALL, INTERSECT, or EXCEPT within the same statement. This is a parser-level restriction rather than a permissions or configuration issue — the query engine cannot determine cursor-updatability semantics when multiple result sets are being merged. It typically surfaces when legacy code (often ported from Oracle or Sybase) or auto-generated ORM queries attempt to declare an updatable cursor over a combined result set.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Query

  • Locate the exact T-SQL batch referenced in the error message using SQL Server Management Studio (SSMS) or Azure Data Studio.
  • Check the DECLARE CURSOR statement for a FOR UPDATE clause combined with UNION, UNION ALL, INTERSECT, or EXCEPT.
  • Run the query in isolation to confirm Error 115 is reproducible outside of the application layer.

Step 2: Refactor the Cursor Logic

  • Split the query into separate DECLARE CURSOR ... FOR UPDATE statements, one per underlying table involved in the set operation.
  • Alternatively, remove the FOR UPDATE clause and instead perform updates using a WHERE CURRENT OF pattern against a single-table subquery, or switch to a read-only cursor combined with a separate UPDATE ... WHERE statement based on the retrieved key values.
  • If the intent was simply to filter and then modify rows, replace the cursor-based logic with a set-based UPDATE statement using a JOIN or MERGE instead of UNION.

Step 3: Update Application or ORM-Generated Code

  • Review any Entity Framework, Hibernate, or legacy Sybase/Oracle migration scripts that auto-generate cursor syntax, since these often produce invalid FOR UPDATE + set operator combinations.
  • Manually patch the generated SQL template or add a custom query override in the data access layer to avoid combining set operators with updatable cursors.
  • Save the corrected script to C:\Scripts\SQL\Fixes\ (or your team’s standard repository path) for version control and future audits.

Step 4: Test in a Non-Production Environment

  • Deploy the corrected script to a staging instance of SQL Server 2025 running on Windows Server 2025 or Windows 11.
  • Execute the batch via sqlcmd -S <ServerName> -i FixedScript.sql to confirm no Error 115 is thrown.
  • Monitor the SQL Server Error Log (Management > SQL Server Logs in SSMS) for any residual syntax warnings.

Alternative or Verification Steps

  • Verify the fix by re-running the original failing procedure or application transaction and confirming that no Error 115 appears in the SQL Server Error Log or client application output.
  • As an alternative, if refactoring the cursor is not feasible short-term, wrap the set-operation query in a temporary table or table variable first, then declare the FOR UPDATE cursor against that single temporary object instead of the combined result set directly.