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

Why This Error Happens

Error 5136 occurs when SQL Server attempts to create or attach a FILESTREAM filegroup container at a directory path that is already nested inside—or is the parent of—an existing FILESTREAM container. SQL Server enforces a strict rule that each FILESTREAM container must occupy its own isolated directory structure, because the filestream.hdr header file and garbage-collection logic cannot safely manage overlapping directory trees. This typically happens when a DBA reuses a parent folder for multiple databases or accidentally points a new FILEGROUP at a subdirectory of an already-provisioned container.

Step-by-Step Resolution Guide

Step 1: Identify the Conflicting Directory Structure

  • Open SQL Server Management Studio (SSMS) and run sys.database_files to list current FILESTREAM paths for all databases on the instance.
  • Check the physical folder structure in Windows Explorer (e.g., D:\SQLData\FileStreamData\) to see if the new path you specified is a child or parent of an existing container folder.
  • Look for a hidden filestream.hdr file in the suspected parent folder — its presence confirms that folder is already a container.

Step 2: Choose a Fully Isolated Path

  • Create a brand-new, empty directory for the new FILESTREAM container, ensuring it is not nested inside or above any existing container (e.g., use D:\SQLData\FS_Container2\ instead of D:\SQLData\FileStreamData\Sub1\).
  • Confirm the new folder does not already exist prior to running the CREATE DATABASE or ALTER DATABASE ... ADD FILE statement — SQL Server must create the final directory itself.
  • Example corrected syntax:
ALTER DATABASE MyDB
ADD FILE (NAME = FS_Data2, FILENAME = 'D:\SQLData\FS_Container2')
TO FILEGROUP FileStreamGroup2;

Step 3: Validate NTFS Permissions and Folder Ownership

  • Ensure the SQL Server service account has Full Control NTFS permissions on the new parent drive/folder (right-click folder → Properties → Security tab).
  • Remove any leftover orphaned FILESTREAM folders from failed previous attempts using rmdir /s in an elevated Command Prompt, provided they are not currently referenced by any active database.

Step 4: Restart the FILESTREAM Configuration if Needed

  • Open SQL Server Configuration Manager → right-click the SQL Server instance → Properties → FILESTREAM tab, and confirm “Enable FILESTREAM for Transact-SQL access” is checked.
  • Restart the SQL Server service after any configuration changes to ensure the new path registers cleanly.

Alternative or Verification Steps

  • Verify the fix by querying sys.master_files and confirming the new FILESTREAM path shows state_desc = ONLINE with no errors in the SQL Server Error Log.
  • If the error persists, drop and recreate the FILEGROUP entirely using a completely new drive letter or root-level folder to eliminate any residual directory nesting conflicts.