Troubleshooting Guide: SQL Server Error 3985 – Transaction Context Change Failure
Why This Error Happens
Error 3985 typically occurs when SQL Server 2025 cannot allocate sufficient memory to switch transaction contexts, often during distributed transactions, linked server queries, or when using sp_getbindtoken and sp_bindsession. This is frequently triggered by memory pressure from the Buffer Pool being set too high relative to available system RAM, or by other processes on Windows Server 2025 competing for physical memory. In some cases, this error is a symptom of memory fragmentation within the SQL Server process rather than true system-wide memory exhaustion.
Step-by-Step Resolution Guide
Step 1: Verify Current Memory Configuration
- Open SQL Server Management Studio (SSMS) and run:
EXEC sp_configure 'max server memory' - Check if the value is set too close to the total physical RAM (leave at least 4-8 GB for the OS on Windows Server 2025).
- Review current usage via:
SELECT * FROM sys.dm_os_process_memory
Step 2: Adjust Max Server Memory Setting
- Run the following to reconfigure, replacing
<value>with an appropriate MB figure (e.g., leave 20% of RAM for the OS):
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'max server memory', <value>;
RECONFIGURE;
- Restart the SQL Server service via
services.mscornet stop MSSQLSERVER && net start MSSQLSERVERfor changes to take full effect.
Step 3: Check for Memory Leaks in Other Processes
- Open Task Manager or Performance Monitor (
perfmon.exe) on Windows Server 2025. - Monitor the counter
Memory\Available MBytes; if it consistently drops below 500 MB, identify and close competing processes (e.g., antivirus scans, backup agents). - Check Windows Event Viewer under Applications and Services Logs > MSSQLSERVER for recurring Out-Of-Memory (OOM) warnings correlating with Error 3985.
Step 4: Review Linked Server and Distributed Transaction Settings
- If the error occurs during cross-database or linked server queries, verify the MSDTC (Distributed Transaction Coordinator) service is running:
services.msc→ check “Distributed Transaction Coordinator”. - Ensure linked server memory-intensive queries are optimized or broken into smaller batches to reduce simultaneous context switches.
Step 5: Apply Latest SQL Server 2025 Cumulative Update
- Navigate to the Microsoft Update Catalog and download the latest Cumulative Update (CU) for SQL Server 2025.
- Install the update and reboot the server, as this error has known fixes related to memory handling in earlier builds.
Alternative or Verification Steps
- To verify the fix, re-run the failing transaction/query and monitor
sys.dm_os_memory_clerksto confirm memory allocation stabilizes without triggering Error 3985. - If the issue persists, consider adding physical RAM to the Windows Server 2025 host or migrating to a dedicated SQL Server instance with reduced concurrent workloads.