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

Troubleshooting Guide: SQL Server Error 6287 — “ALTER ASSEMBLY failed because the function no longer satisfies indexability requirements”

Why This Error Happens

This error occurs when a SQLCLR user-defined function marked as deterministic and precise (used in a computed column index or persisted computed column) is modified in a way that violates the strict indexability rules enforced by SQL Server. Typically, this happens when the updated assembly code changes the function’s DataAccess, SystemDataAccess, or IsDeterministic attributes, or introduces non-deterministic logic (such as calls to system functions, random values, or external resources) while the function is still referenced by an index or persisted computed column. SQL Server blocks the ALTER ASSEMBLY operation to prevent silent index corruption that would result from indexing a function whose output can no longer be guaranteed consistent for the same inputs.

Step-by-Step Resolution Guide

Step 1: Identify the Dependent Indexes and Computed Columns

  • Run the following query to find objects depending on the CLR function:
SELECT referencing_schema_name, referencing_entity_name, referencing_class_desc
FROM sys.dm_sql_referencing_entities('dbo.YourFunctionName', 'OBJECT');
  • Cross-reference results against sys.indexes and sys.computed_columns to confirm which indexes or persisted columns use the function.
  • Note down the exact index names and computed column definitions for later recreation.

Step 2: Drop the Dependent Indexes and Persisted Computed Columns

  • Script out and drop any indexes built on the computed column that calls the CLR function:
DROP INDEX IX_YourIndexName ON dbo.YourTable;
  • If the computed column itself is persisted, either drop it or alter it to remove the PERSISTED keyword:
ALTER TABLE dbo.YourTable
ALTER COLUMN YourComputedColumn DROP PERSISTED;
  • Save these DDL scripts in a .sql file under C:\SQLFixes\Assembly6287\ for rollback and reapplication later.

Step 3: Validate and Correct the Assembly’s Determinism Attributes

  • Open the CLR project source (typically a .cs file in your Visual Studio solution) and inspect the SqlFunction attribute decoration:
[SqlFunction(IsDeterministic = true, DataAccess = DataAccessKind.None)]
  • Ensure the function body does not call non-deterministic methods (e.g., DateTime.Now, Guid.NewGuid(), or external I/O) — these will break indexability even if the attribute claims determinism.
  • Rebuild the .dll and redeploy using:
ALTER ASSEMBLY YourAssemblyName
FROM 'C:\Deploy\YourAssembly.dll'
WITH PERMISSION_SET = SAFE;

Step 4: Recreate the Computed Column and Rebuild Indexes

  • Re-add the PERSISTED keyword or recreate the computed column using the corrected function:
ALTER TABLE dbo.YourTable
ALTER COLUMN YourComputedColumn AS dbo.YourFunctionName(InputColumn) PERSISTED;
  • Recreate the previously dropped indexes using the scripts saved in Step 2:
CREATE INDEX IX_YourIndexName ON dbo.YourTable(YourComputedColumn);

Step 5: Confirm Assembly Permission Set and SQL Server CLR Configuration

  • Verify CLR integration is still enabled on the instance (especially after a Windows Server 2025 OS upgrade or SQL Server 2025 patch):
EXEC sp_configure 'clr enabled';
  • If disabled, re-enable it with:
EXEC sp_configure 'clr enabled', 1;
RECONFIGURE;

Alternative or Verification Steps

  • After redeployment, run SELECT OBJECTPROPERTY(OBJECT_ID('dbo.YourFunctionName'), 'IsDeterministic'); — it should return 1 to confirm the function is now correctly flagged as deterministic.
  • If the error persists, drop the assembly entirely (DROP ASSEMBLY YourAssemblyName WITH NO DEPENDENTS;) and perform a clean CREATE ASSEMBLY deployment rather than an in-place ALTER, as corrupted metadata from prior failed alters can sometimes linger in sys.assembly_modules.