Troubleshooting Guide: SQL Server Error 562 – “Failed to access file ‘%.*ls’. Files can be accessed only through shares”
Why This Error Happens
This error occurs when SQL Server 2025 attempts to access a database file (such as an .mdf, .ldf, or .ndf file) using a local drive path (e.g., D:\Data\file.mdf) instead of a UNC share path, which is a requirement when SQL Server is running in a Failover Cluster Instance (FCI) or a configuration that mandates network share access for storage. It typically indicates that the storage path was registered incorrectly during database creation or attachment, or that the underlying share configuration was changed/removed after the database was already pointing to it. This is common in Storage Spaces Direct (S2D), Scale-Out File Server (SOFS), or Azure Stack HCI deployments where SQL Server enforces share-based access for data resiliency.
Step-by-Step Resolution Guide
Step 1: Verify the Current File Path Configuration
- Run
SELECT name, physical_name FROM sys.master_files;in SQL Server Management Studio (SSMS) to identify the exact path SQL Server is using for the affected database file. - Check if the
physical_namecolumn shows a local path (e.g.,C:\SQLData\) instead of a UNC path (e.g.,\\SOFS01\SQLShare\). - Confirm whether the instance is part of a Failover Cluster Instance (FCI) via
SELECT SERVERPROPERTY('IsClustered');.
Step 2: Recreate or Validate the File Share
- Open Server Manager on Windows Server 2025 and navigate to File and Storage Services > Shares.
- Ensure the share hosting the SQL data files is still active and has not been deleted or renamed.
- Verify NTFS and Share-level permissions grant Full Control to the SQL Server service account (e.g.,
NT SERVICE\MSSQLSERVERor the domain service account used by the Cluster). - Recreate the share if missing using PowerShell:
New-SmbShare -Name "SQLShare" -Path "D:\SQLData" -FullAccess "DOMAIN\SQLServiceAccount"
Step 3: Update the Database File Path to Use UNC Notation
- Take the database offline temporarily using
ALTER DATABASE [YourDB] SET OFFLINE;. - Move or confirm the physical file resides on the shared storage location.
- Update the metadata using:
ALTER DATABASE [YourDB] MODIFY FILE (NAME = YourLogicalFileName, FILENAME = '\\SOFS01\SQLShare\YourDB.mdf');
- Bring the database back online:
ALTER DATABASE [YourDB] SET ONLINE;.
Step 4: Restart SQL Server Service and Validate Cluster Resources
- Restart the SQL Server service via SQL Server Configuration Manager or
Restart-Service MSSQLSERVERin PowerShell (run as Administrator). - If running in a Failover Cluster, use Failover Cluster Manager to confirm the SQL Server resource comes online without triggering Error 562 again.
- Check the SQL Server Error Log (
ERRORLOGfile location) for confirmation that the file was accessed successfully post-restart.
Alternative or Verification Steps
- Verify the fix by querying
sys.master_filesagain to confirm allphysical_nameentries now show valid UNC paths, and attempt a manualRESTOREorATTACHoperation on the affected database to ensure no errors are thrown. - If the issue persists, use Robocopy to migrate the database files entirely to a validated SOFS/S2D share and re-attach the database from that new UNC location using
CREATE DATABASE ... FOR ATTACH.