Troubleshooting Guide: DBCC Error 2572 — “DBCC cannot free DLL. The DLL is in use.”
Why This Error Happens
This error occurs when DBCC FREESYSTEMCACHE or a similar DBCC command attempts to unload an extended stored procedure DLL that still has active threads or open references within SQL Server’s memory space. It typically happens because another session or background process (such as a lingering extended procedure call) has not released its handle to the DLL. In rarer cases, this can also indicate a corrupted or improperly registered extended procedure DLL that fails to clean up its resources during unload.
Step-by-Step Resolution Guide
Step 1: Identify Active Sessions Using the DLL
- Run the following query to check for active extended stored procedure calls:
SELECT * FROM sys.dm_exec_requests WHERE command LIKE '%XP%';
- Check SQL Server error logs at
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOGfor related entries referencing the DLL name. - Note the specific DLL mentioned in the error (replace
%.*lswith the actual name from your error output).
Step 2: Terminate Blocking Sessions
- Identify the session ID (SPID) holding the DLL reference using:
SELECT session_id, status, last_request_start_time
FROM sys.dm_exec_sessions WHERE is_user_process = 1;
- Safely terminate the blocking session with:
KILL <SPID>;
- Avoid killing system SPIDs (values below 50), as this can destabilize the instance.
Step 3: Re-register or Replace the Extended Procedure DLL
- Navigate to the Binn folder, typically located at:
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Binn\ - If the DLL is a custom extended stored procedure, drop and re-add it using:
EXEC sp_dropextendedproc 'xp_yourprocedure';
EXEC sp_addextendedproc 'xp_yourprocedure', 'yourdll.dll';
- If the file appears corrupted, replace it with a verified backup copy and restart the SQL Server service via Services.msc or:
Restart-Service -Name 'MSSQLSERVER'
Step 4: Restart the SQL Server Service (If Needed)
- If the DLL remains locked after killing sessions, perform a full service restart to force memory release:
net stop MSSQLSERVER
net start MSSQLSERVER
- Confirm no orphaned
sqlservr.exeprocesses remain in Task Manager before restarting.
Alternative or Verification Steps
- Re-run
DBCC FREESYSTEMCACHE('ALL')after completing the steps above; the command should complete without raising Error 2572. - If the issue persists, use Process Explorer (Sysinternals) to confirm no external applications or orphaned threads are holding a handle to the DLL file in the Binn directory.