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

Troubleshooting Guide: Error 5185 – FILESTREAM Log File Mismatch

Why This Error Happens

Error 5185 occurs when SQL Server 2025 attempts to attach or recover a database and discovers that the FILESTREAM data container on disk does not contain a matching filestream.hdr log record, or the container’s internal GUID does not align with what is registered in the primary database files. This typically happens after an improper file copy (using Windows Explorer instead of a proper backup/restore), a failed or interrupted detach operation, or because the FILESTREAM container was moved/restored without its accompanying transaction log metadata. It can also surface when antivirus or backup software locks or modifies files inside the FILESTREAM container folder, corrupting the internal RSRC/log stream structure.

Step-by-Step Resolution Guide

Step 1: Verify the FILESTREAM Container Structure

  • Navigate to the FILESTREAM data container path (e.g., D:\SQLData\FileStreamContainer\).
  • Confirm the presence of the hidden filestream.hdr file and the $FSLOG folder.
  • Use dir /a in Command Prompt to reveal hidden system files, since Windows Explorer may hide these by default.
  • If either filestream.hdr or $FSLOG is missing or has a size of 0 KB, the container is corrupted and cannot be auto-repaired.

Step 2: Detach and Properly Reattach the Database

  • Run EXEC sp_detach_db 'YourDatabaseName', 'true'; in SQL Server Management Studio (SSMS) to cleanly detach without losing FILESTREAM pointers.
  • Move the entire database folder (not just the .mdf/.ldf) as a single unit to the new location if relocating.
  • Reattach using CREATE DATABASE YourDatabaseName ON (FILENAME = 'D:\SQLData\YourDB.mdf'), (FILENAME = 'D:\SQLData\YourDB_log.ldf'), (FILENAME = 'D:\SQLData\FileStreamContainer') FOR ATTACH;

Step 3: Restore From a Valid Backup Instead of Manual Copy

  • If the container is confirmed corrupted (Step 1), do not attempt manual repair; restore the full database and FILESTREAM filegroup from the last known good .bak file.
  • Use RESTORE DATABASE YourDatabaseName FROM DISK = 'D:\Backups\YourDB.bak' WITH REPLACE, RECOVERY;
  • Ensure the RESTORE statement includes both the FILESTREAM filegroup and standard filegroups in a single operation.

Step 4: Check Antivirus and Backup Agent Exclusions

  • Open Windows Security settings or your third-party antivirus console on Windows Server 2025.
  • Add an exclusion rule for the entire FILESTREAM container directory path to prevent real-time scanning from locking or altering the $FSLOG stream during write operations.
  • Restart the SQL Server service (net stop MSSQLSERVER && net start MSSQLSERVER) after applying exclusions.

Alternative or Verification Steps

  • Run DBCC CHECKDB('YourDatabaseName') WITH DATA_PURITY; after reattaching to confirm no further consistency errors are reported.
  • If the container remains unrecoverable, use ALTER DATABASE YourDatabaseName REMOVE FILE FileStreamGroupName; to drop the broken filegroup and recreate it fresh, then reload FILESTREAM data from your application-layer backup source.