Troubleshooting Guide: SQL Server Error 3058 – File or Device Name Exceeds Supported Limit
Why This Error Happens
This error occurs when a backup or restore operation references a file path, device name, or logical backup name that exceeds the maximum character limit supported by SQL Server (typically 260 characters, though this can vary by context and API used). It is commonly triggered by deeply nested folder structures, overly descriptive backup file names, or scripts that dynamically generate timestamps and metadata into the file name. SQL Server truncates the name to proceed, but this can lead to unexpected file overwrites, failed backup chains, or confusion when locating the resulting file.
Step-by-Step Resolution Guide
Step 1: Identify the Offending File Path or Device Name
- Review the full error message in SQL Server Error Logs (via SQL Server Management Studio under Management > SQL Server Logs) to see the exact truncated value and the %d limit specified.
- Check the T-SQL script or SQL Server Agent Job step that issued the
BACKUP DATABASEorRESTOREcommand, paying close attention to theTO DISK =orTO URL =clause. - Count the full character length of the path, including the drive letter, all subfolders, and the file extension (e.g.,
.bakor.trn).
Step 2: Shorten the File Path and Name
- Move the backup destination closer to the root drive (e.g., change
D:\SQLBackups\Production\Daily\FullBackups\2025\November\toD:\Backups\). - Simplify dynamic naming conventions in maintenance plans or scripts; avoid including excessive details like full server names, instance names, and long timestamps in a single string.
- If using a Maintenance Plan Wizard, edit the Back Up Database Task and manually override the auto-generated folder/file structure with a shorter, flatter path.
Step 3: Enable Long Path Support (If Applicable)
- On Windows Server 2025 or Windows 11, verify if the Group Policy for long path behavior is enabled, as SQL Server relies on underlying OS path limitations in some scenarios.
- Open the Local Group Policy Editor (
gpedit.msc) and navigate to Computer Configuration > Administrative Templates > System > Filesystem. - Enable the “Enable Win32 long paths” policy setting and restart the SQL Server service for the change to take effect.
Step 4: Rewrite the Backup/Restore Script
- Update the
BACKUP DATABASE [YourDB] TO DISK = N'Path'command in your script to use the newly shortened path. - Test the command manually in SQL Server Management Studio (SSMS) before re-enabling it in a scheduled SQL Server Agent Job.
- If using PowerShell or
sqlcmdfor automation, ensure variables building the path string are concatenated correctly without extra directory duplication.
Alternative or Verification Steps
- Run the backup command again and monitor the SQL Server Error Log; confirm that Error 3058 no longer appears and the file is created at the expected (non-truncated) path.
- If shortening the path is not feasible due to organizational naming policies, consider mapping a Windows Drive Letter or using a
SUBSTcommand to point to a deeply nested folder, effectively reducing the perceived path length SQL Server has to process.