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

Troubleshooting Guide: SQL Server Error 7903 – Orphaned FILESTREAM Files

Why This Error Happens

Error 7903 occurs when DBCC CHECKDB detects files present in the FILESTREAM data container that have no corresponding pointer or reference in the database’s internal metadata tables. This typically happens after an improperly terminated transaction, an unexpected server shutdown during a FILESTREAM write operation, or manual tampering with the FILESTREAM directory structure outside of SQL Server’s control. Because the garbage collector for FILESTREAM runs as a background checkpoint process, a crash before this cleanup cycle completes can leave these “orphaned” physical files on disk while SQL Server’s metadata remains unaware of them.

Step-by-Step Resolution Guide

Step 1: Run a Diagnostic Scan to Confirm Scope

  • Open SQL Server Management Studio (SSMS) and connect to the affected instance on your Windows Server 2025 host.
  • Execute DBCC CHECKDB ('YourDatabaseName') WITH NO_INFOMSGS, ALL_ERRORMSGS; to get a full list of every orphaned file ID associated with the container.
  • Note the specific Container ID and Directory ID referenced in the error output, as you will need these to locate the physical files.

Step 2: Locate the Physical FILESTREAM Container

  • Navigate to the file system path where the FILESTREAM data is stored. This is typically found under a path similar to D:\SQLData\FileStreamContainer\ or wherever you configured the FILESTREAM_ON schema during table creation.
  • Use Windows PowerShell to cross-reference the GUID folder names (Directory IDs) with the IDs reported in the error message: Get-ChildItem -Path "D:\SQLData\FileStreamContainer" -Recurse.
  • Identify the specific orphaned file(s) matching the error log, ensuring you do not delete active transaction logs or $FSLOG tracking files accidentally.

Step 3: Execute a Targeted Repair

  • Take the database offline for single-user mode access to prevent write locks during the repair: ALTER DATABASE YourDatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
  • Run the specific repair command: DBCC CHECKDB ('YourDatabaseName', REPAIR_REBUILD);.
  • Note: If REPAIR_REBUILD does not clear the orphaned file flags because the data is truly disconnected, you may need to escalate to REPAIR_ALLOW_DATA_LOSS, which will force SQL Server to delete the physical orphaned file from the OS container to match the metadata state.

Step 4: Restore Multi-User Access and Cleanup

  • Set the database back to multi-user mode: ALTER DATABASE YourDatabaseName SET MULTI_USER;
  • Verify Windows Server 2025 file permissions on the FILESTREAM share to ensure the SQL Server service account (NT Service\MSSQLSERVER) still has Full Control, as permission drift can sometimes trigger false-positive orphaned file detections.

Alternative or Verification Steps

  • Verify the Fix: Re-run DBCC CHECKDB ('YourDatabaseName') WITH NO_INFOMSGS; immediately after the repair. If the output returns “0 allocation errors and 0 consistency errors,” the orphaned file issue (Error 7903) has been successfully resolved.
  • Alternative Method: If REPAIR_ALLOW_DATA_LOSS fails due to active file handles, restart the “SQL Server FILESTREAM” service via services.msc on the Windows Server 2025 machine to release file locks before attempting the repair sequence again.