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

Troubleshooting Guide: SQL Server Error 5087 – File Content Type Mismatch

Why This Error Happens

Error 5087 occurs when SQL Server detects that a file being added, attached, or referenced does not match the expected content type of its target filegroup. This typically happens when attempting to add a regular data file (.mdf/.ndf) to a FILESTREAM filegroup, or vice versa, or when a database file has become mislabeled due to metadata corruption during a migration or restore. It can also occur after manually editing file properties in system catalog views or when attaching a database with inconsistent file-to-filegroup mappings.

Step-by-Step Resolution Guide

Step 1: Verify the Filegroup Type Before Adding Files

  • Run the following query to inspect filegroup types in the target database:
  • SELECT name, type, type_desc FROM sys.filegroups;
  • Confirm whether the filegroup is ROWS, FILESTREAM, or MEMORY_OPTIMIZED_DATA before attempting to add a file.
  • Ensure you are not trying to add a standard .ndf file to a FILESTREAM or MEMORY_OPTIMIZED_DATA filegroup.

Step 2: Correct the File Addition Command

  • If adding a FILESTREAM file, ensure the filegroup was created with CONTAINS FILESTREAM:
  • ALTER DATABASE YourDB ADD FILEGROUP FS_Group CONTAINS FILESTREAM;
  • Then add the file using a directory path, not a physical file path:
  • ALTER DATABASE YourDB ADD FILE (NAME = FS_Data, FILENAME = 'C:\SQLData\FSFolder') TO FILEGROUP FS_Group;
  • For standard data files, ensure you are targeting a ROWS filegroup only.

Step 3: Check for Metadata Corruption in System Catalogs

  • Query sys.database_files and sys.master_files to confirm consistency between file IDs and filegroup IDs:
  • SELECT file_id, type_desc, data_space_id FROM sys.database_files;
  • If mismatches are found (e.g., a FILESTREAM file pointing to a ROWS filegroup ID), the database metadata may be corrupted.
  • Run DBCC CHECKDB('YourDB') WITH NO_INFOMSGS, ALL_ERRORMSGS; to identify broader consistency issues.

Step 4: Rebuild or Recreate the Problematic Filegroup

  • If corruption is confirmed, create a new filegroup of the correct type:
  • ALTER DATABASE YourDB ADD FILEGROUP NewFSGroup CONTAINS FILESTREAM;
  • Migrate data using BCP, SELECT INTO, or FILESTREAM data export tools as appropriate.
  • Remove the corrupted filegroup once data migration is verified:
  • ALTER DATABASE YourDB REMOVE FILEGROUP OldFSGroup;

Step 5: Restart SQL Server Service and Re-Test

  • On Windows Server 2025 / Windows 11, restart the SQL Server service via:
  • Services.msc → SQL Server (MSSQLSERVER) → Restart
  • Alternatively use PowerShell: Restart-Service -Name 'MSSQLSERVER'
  • Re-attempt the original file/filegroup operation to confirm the error no longer appears.

Alternative or Verification Steps

  • Verify the fix by re-running SELECT name, type_desc FROM sys.filegroups; and confirming the new file’s type_desc in sys.database_files matches the target filegroup type exactly.
  • If the issue persists after metadata correction, restore the database from a known-good backup taken before the mismatch was introduced, then reapply any pending transactions via transaction log backups.