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

Troubleshooting Guide: SQL Server Error 5305 — Invalid rowdump/lockres Column Access

Why This Error Happens

This error occurs when a query attempts to select the %%lockres%% or rowdump-style virtual columns against an indexed view without explicitly including the NOEXPAND hint in the query. SQL Server 2025 requires NOEXPAND in these cases because, without it, the query optimizer is free to expand the view definition back into its underlying base tables, making row-locator metadata (like lockres) ambiguous or impossible to resolve. Essentially, the engine cannot guarantee a stable physical row reference unless it is forced to read directly from the materialized indexed view structure.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Query

  • Locate the T-SQL statement referencing %%lockres%% or rowdump in the SELECT list.
  • Confirm the target object is an indexed view (check sys.views and sys.indexes for a clustered index on the view).
  • Example of a failing query:
  SELECT %%lockres%% FROM dbo.vw_SalesSummary;

Step 2: Add the NOEXPAND Hint to the Query

  • Modify the FROM clause to explicitly include WITH (NOEXPAND) immediately after the view name.
  • Updated query should look like:
  SELECT %%lockres%% 
  FROM dbo.vw_SalesSummary WITH (NOEXPAND);
  • If the query joins multiple objects, ensure NOEXPAND is applied only to the indexed view, not to standard base tables.

Step 3: Validate the Indexed View Still Exists and Is Usable

  • Run the following to confirm the view has a valid clustered index (required for NOEXPAND to work):
  SELECT i.name, i.type_desc 
  FROM sys.indexes i 
  JOIN sys.views v ON i.object_id = v.object_id 
  WHERE v.name = 'vw_SalesSummary';
  • If no clustered index exists, you cannot use NOEXPAND; you will need to create one via CREATE UNIQUE CLUSTERED INDEX on the view first.

Step 4: Update Application Code or Stored Procedures

  • Search application-layer code, ORM-generated queries, and stored procedures for any dynamic SQL hitting this view without the hint.
  • Patch all instances consistently, especially in reporting tools or diagnostic scripts that rely on lockres for row-versioning or conflict detection logic.

Alternative or Verification Steps

  • Re-run the original query with WITH (NOEXPAND) added and confirm Error 5305 no longer appears in SSMS or the application log.
  • If NOEXPAND cannot be used due to application constraints, consider querying the underlying base tables directly instead of the indexed view when lockres/rowdump values are required.