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

Troubleshooting Guide: SQL Server Error 5518 — FILESTREAM Path Too Long

Why This Error Happens

Error 5518 occurs when the fully qualified FILESTREAM data container path exceeds the maximum path length supported by SQL Server, which is typically capped well below the Windows MAX_PATH (260 character) limit once internal subdirectory structures and GUID-based file names are appended. This commonly happens when a FILESTREAM filegroup is created inside a deeply nested folder structure, or when a database name, filegroup name, or logical file name is excessively long and gets concatenated into the physical directory path. It can also surface after migrating databases to Windows Server 2025 where backup/restore operations preserve an original long path structure from a different server environment.

Step-by-Step Resolution Guide

Step 1: Identify the Current FILESTREAM Path Length

  • Run the following query to locate the FILESTREAM-enabled filegroup and its root directory:
  SELECT name, physical_name FROM sys.master_files WHERE type_desc = 'FILESTREAM';
  • Manually count the character length of the path, including the database name folder and any GUID subfolders SQL Server will generate at runtime (these add roughly 40–50 characters).
  • Confirm whether the path exceeds 260 characters (standard) or approaches the ~32,000 character limit if long paths are enabled but still causing internal truncation issues.

Step 2: Shorten the Directory Structure

  • Move or recreate the FILESTREAM data container closer to the drive root, for example using D:\FSDATA\ instead of a nested path like D:\SQLServer\Databases\Production\FileStreamContainers\2025\.
  • Rename overly long database names, filegroup names, or logical file names, since SQL Server appends these directly into the physical FILESTREAM folder structure.
  • Use ALTER DATABASE to add a new FILESTREAM filegroup pointing to the shortened path:
  ALTER DATABASE YourDB ADD FILEGROUP FS_Filegroup CONTAINS FILESTREAM;
  ALTER DATABASE YourDB ADD FILE (NAME='FSData', FILENAME='D:\FSDATA\') TO FILEGROUP FS_Filegroup;

Step 3: Enable Long Path Support (If Shortening Isn’t Feasible)

  • Open Group Policy Editor (gpedit.msc) and navigate to Computer Configuration > Administrative Templates > System > Filesystem.
  • Enable “Enable Win32 long paths” and restart Windows Server 2025 or Windows 11 for the policy to take effect.
  • Alternatively, set the registry key directly:
  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
  LongPathsEnabled = 1 (DWORD)
  • Restart the SQL Server service afterward so it picks up the updated filesystem policy.

Step 4: Migrate Existing FILESTREAM Data

  • If the filegroup already contains data, create the new shortened-path filegroup first, then migrate BLOB data using UPDATE statements or INSERT INTO ... SELECT into tables mapped to the new filegroup.
  • Drop the old, overly long FILESTREAM filegroup only after confirming successful migration and application connectivity.
  • Validate file integrity using DBCC CHECKDB after the migration completes.

Alternative or Verification Steps

  • Verify the fix by inserting a new FILESTREAM BLOB record and confirming no Error 5518 appears in the SQL Server error log or Event Viewer (Event ID source: MSSQLSERVER).
  • If the error persists, check for antivirus or backup software intercepting the FILESTREAM container path, as some third-party agents reconstruct even longer UNC-style paths that re-trigger the limit.