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

Troubleshooting Guide: SQL Server Error 5522 (FILESTREAM Data File Removal Failure)

Why This Error Happens

Error 5522 occurs when SQL Server 2025 attempts to remove a FILESTREAM data file or filegroup while the associated transaction log still contains inactive log records that have not been captured by a log backup. Because FILESTREAM operations are logged similarly to standard data modifications, SQL Server enforces a rule that prevents file removal until the log is truncated via a proper backup, ensuring the database remains in a recoverable and consistent state. This typically happens on databases using the FULL or BULK_LOGGED recovery model where scheduled log backups have been missed, disabled, or misconfigured.

Step-by-Step Resolution Guide

Step 1: Verify the Database Recovery Model and Log Status

  • Open SQL Server Management Studio (SSMS) and connect to your SQL Server 2025 instance.
  • Run the following query to check the recovery model and log reuse wait description:
SELECT name, recovery_model_desc, log_reuse_wait_desc 
FROM sys.databases 
WHERE name = 'YourDatabaseName';
  • If log_reuse_wait_desc shows LOG_BACKUP, this confirms the root cause.

Step 2: Perform a Transaction Log Backup

  • Execute a log backup to clear the inactive portion of the log and allow truncation:
BACKUP LOG [YourDatabaseName] 
TO DISK = 'C:\SQLBackups\YourDatabaseName_Log.trn';
  • Ensure the backup destination folder exists on the Windows Server 2025 host and that the SQL Server service account has write permissions to C:\SQLBackups\.
  • If no full backup exists yet, run a full database backup first before attempting the log backup.

Step 3: Retry the FILESTREAM File Removal

  • After the log backup completes successfully, re-attempt the original command to remove the FILESTREAM file:
ALTER DATABASE [YourDatabaseName] 
REMOVE FILE [YourFileStreamLogicalName];
  • Confirm there are no open transactions or active sessions referencing the FILESTREAM filegroup using:
SELECT * FROM sys.dm_tran_active_transactions;

Step 4: Configure Scheduled Log Backups to Prevent Recurrence

  • Open SQL Server Management Studio → SQL Server Agent → Jobs.
  • Create or verify a maintenance plan that runs transaction log backups at regular intervals (e.g., every 15–30 minutes).
  • Alternatively, use Ola Hallengren’s Maintenance Solution scripts for automated log backup scheduling on Windows Server 2025 environments.

Alternative or Verification Steps

  • Verify the fix by re-running the log_reuse_wait_desc query from Step 1 — it should now return NOTHING instead of LOG_BACKUP.
  • If log backups are not required for your environment (e.g., test/dev systems), switch the database to the SIMPLE recovery model using ALTER DATABASE [YourDatabaseName] SET RECOVERY SIMPLE; to bypass the log backup requirement entirely before removing the FILESTREAM file.