Why This Error Happens
Error 172 occurs because the HOLDLOCK hint (or its equivalent SERIALIZABLE/REPEATABLE READ isolation level) is fundamentally incompatible with FOR BROWSE mode queries in SQL Server 2025. Browse mode relies on a specific row-versioning and locking mechanism to support client-side cursors, and it cannot coexist with the persistent shared locks that HOLDLOCK requests. This is typically triggered by legacy application code, ORM-generated queries, or ODBC/OLE DB drivers that append both clauses to the same SELECT statement without validation.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Query
- Enable SQL Server Profiler or Extended Events (
sqlserver.error_reported) filtered on Error Number = 172. - Capture the exact T-SQL batch text, including the
SELECT ... FOR BROWSEclause. - Check application logs in
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOGfor the corresponding timestamp.
Step 2: Remove or Replace the HOLDLOCK Hint
- Open the query in SQL Server Management Studio (SSMS) 21 and locate the
WITH (HOLDLOCK)table hint. - Delete
HOLDLOCKfrom the query ifFOR BROWSEis required for cursor-based client access. - If transactional consistency is needed instead, replace
FOR BROWSEwith a standard cursor-based approach usingSET TRANSACTION ISOLATION LEVEL SERIALIZABLEat the session level rather than an inline hint.
Step 3: Update Application/Driver Configuration
- Check the connection string or ODBC Data Source settings in
Control Panel > ODBC Data Sources (64-bit)on Windows Server 2025 / Windows 11. - Ensure legacy DB-Library or ODBC drivers are not auto-injecting
HOLDLOCKhints when browse mode is enabled (common in older client applications). - Update the driver to the latest Microsoft ODBC Driver 18+ for SQL Server, downloadable via
winget install Microsoft.msodbcsql.
Step 4: Validate Query Execution Plan
- Re-run the corrected query in SSMS with Include Actual Execution Plan enabled.
- Confirm no locking hint conflicts appear in the Messages tab.
- Deploy the fix to a staging environment before pushing to production servers.
Alternative or Verification Steps
- Re-execute the original failing stored procedure or application call and confirm Error 172 no longer appears in
ERRORLOGor the SSMS Messages pane. - If the application cannot be modified, consider migrating away from
FOR BROWSEentirely in favor of API Server cursors (SQLSetStmtAttrwithSQL_ATTR_CURSOR_TYPE) which support isolation-level locking without this restriction.