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

Troubleshooting Guide: SQL Server Error 10304 – Failed to Enter CLR Host

Why This Error Happens

Error 10304 occurs when SQL Server’s SQLCLR hosting layer cannot successfully initialize or enter the .NET Common Language Runtime, typically because the server is under memory pressure or has hit a virtual address space limit. This can also stem from a misconfigured max server memory setting that leaves insufficient room for the CLR to allocate its AppDomain, or from a corrupted/outdated .NET runtime installation that SQL Server 2025 depends on. In some cases, it is triggered by excessive concurrent CLR AppDomains being spun up without being unloaded, exhausting available worker threads or memory pools.

Step-by-Step Resolution Guide

Step 1: Check and Adjust SQL Server Memory Configuration

  • Open SQL Server Management Studio (SSMS) and run EXEC sp_configure 'max server memory (MB)'; to review current limits.
  • Ensure max server memory is not set so high that it starves the OS and CLR of physical RAM; a common rule is to leave at least 10-20% of total RAM (minimum 4 GB) for the OS and CLR overhead.
  • Reconfigure using EXEC sp_configure 'max server memory (MB)', <new_value>; RECONFIGURE;.

Step 2: Verify and Repair the .NET Runtime Dependency

  • Navigate to Control Panel > Programs > Programs and Features on Windows Server 2025 / Windows 11 and confirm the .NET runtime version required by SQL Server 2025 is installed and not flagged as corrupted.
  • Run sfc /scannow from an elevated Command Prompt to check for corrupted system files that may affect the CLR.
  • If corruption is found, repair or reinstall the .NET Framework/Runtime via the offline installer from the Microsoft Download Center.

Step 3: Review and Limit Active CLR AppDomains

  • Query active CLR sessions using SELECT * FROM sys.dm_clr_appdomains; to identify if too many AppDomains are loaded simultaneously.
  • If excessive AppDomains are present, restart the SQL Server instance during a maintenance window to flush the CLR host state: net stop MSSQLSERVER && net start MSSQLSERVER.
  • Review any custom CLR assemblies for memory leaks or unclosed handles that may prevent AppDomain unloading.

Step 4: Increase Virtual Address Space or Enable Lock Pages in Memory

  • Open secpol.msc (Local Security Policy) on the Windows Server 2025 host and navigate to Local Policies > User Rights Assignment.
  • Add the SQL Server service account to the Lock pages in memory policy to prevent the OS from paging out critical SQL Server memory needed by the CLR.
  • Restart the SQL Server service for the policy change to take effect.

Alternative or Verification Steps

  • To verify the fix, run a test CLR-based stored procedure or function and check the SQL Server Error Log (EXEC sp_readerrorlog;) to confirm Error 10304 no longer appears.
  • If the issue persists, as an alternative, temporarily disable and re-enable CLR integration entirely using EXEC sp_configure 'clr enabled', 0; RECONFIGURE; EXEC sp_configure 'clr enabled', 1; RECONFIGURE; to force a clean re-initialization of the hosting environment.