Troubleshooting Guide: SQL Server Error 12425
Why This Error Happens
This error occurs because the query you are attempting to delete is currently protected by an active Query Store forcing policy. SQL Server 2025 prevents the removal of query metadata while a specific execution plan is being forced on that query ID, as doing so would orphan the forcing policy and potentially destabilize execution plan consistency. This typically happens when an administrator attempts to clean up the Query Store catalog views or run sp_query_store_remove_query without first un-forcing the associated plan.
Step-by-Step Resolution Guide
Step 1: Identify the Forced Plan Status
- Open SQL Server Management Studio (SSMS) and connect to the target instance on Windows Server 2025.
- Run the following query to check the
is_forced_plancolumn for the specific Query ID: SELECT * FROM sys.query_store_plan WHERE query_id = <Your_Query_ID> AND is_forced_plan = 1;- Confirm that the
force_failure_countandlast_force_failure_reasonare not null, indicating an active lock on the deletion process.
Step 2: Unforce the Execution Plan
- Before deleting the query, you must release the forcing policy using the system stored procedure
sp_query_store_unforce_plan. - Execute the following T-SQL command, replacing the IDs with your specific values:
EXEC sp_query_store_unforce_plan @query_id = <Your_Query_ID>, @plan_id = <Your_Plan_ID>;- Verify the command completes without returning Error 12425 or related permission errors (ensure you have
db_ownerorALTERpermissions on the database).
Step 3: Clear the Query from Query Store
- Once the plan is confirmed as unforced, proceed with the removal of the query entry.
- Run the cleanup procedure to remove the specific query data:
EXEC sp_query_store_remove_query @query_id = <Your_Query_ID>;- If the error persists, restart the SQL Server service via the Services app (
services.msc) on Windows Server 2025 to clear any cached Query Store memory locks, then repeat the step.
Step 4: Check for Automatic Plan Correction Conflicts
- If SQL Server 2025’s automatic tuning feature (Automatic Plan Correction) is enabled, it may be re-forcing the plan immediately after you unforce it.
- Navigate to Database Properties > Automatic Tuning in SSMS and temporarily disable “Force Last Good Plan” for the duration of the maintenance window.
- Re-attempt the deletion command from Step 3 once automatic tuning is paused.
Alternative or Verification Steps
- Verify the Fix: Query the
sys.query_store_queryview to ensure the specificquery_idno longer returns a row, confirming successful deletion. - Alternative Solution: If the specific query cannot be unforced due to corruption, use
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;followed byALTER DATABASE [YourDB] SET QUERY_STORE CLEAR;to perform a full reset of the Query Store (Note: this will delete all Query Store history, not just the single query).