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

Troubleshooting Guide: SQL Server Error 3057 – Invalid Device Name

Why This Error Happens

This error occurs when the device name (path and filename) specified in a BACKUP or RESTORE statement exceeds the maximum character limit supported by SQL Server. This is typically caused by overly long UNC paths, deeply nested folder structures, or excessively long auto-generated backup file names (common in maintenance plans or scripted backup jobs). SQL Server 2025 enforces a strict length cap on the physical device name string, and exceeding it—even by a few characters—will trigger this error and abort the backup operation.

Step-by-Step Resolution Guide

Step 1: Identify the Full Length of the Backup Path

  • Open the failing BACKUP DATABASE or BACKUP LOG script in SQL Server Management Studio (SSMS).
  • Count the total character length of the TO DISK = 'path' value, including drive letter, folder names, and file extension.
  • Remember the supported limit is typically 260 characters for standard paths (or lower depending on the device type referenced in the error message).

Step 2: Shorten the File Path and Folder Structure

  • Move the backup destination to a shorter root path, e.g., change D:\SQLBackups\ProductionServers\2025\DailyFull\CompanyDatabase_FullBackup.bak to D:\Backups\CompanyDB.bak.
  • Avoid deeply nested subfolders when configuring Maintenance Plans or backup jobs.
  • If using UNC paths (e.g., \\FileServer01\SQLBackups\...), shorten the share name or map a drive letter to reduce the string length.

Step 3: Adjust Dynamic Naming Conventions in Scripts or Maintenance Plans

  • If using a SQL Agent Job or Maintenance Plan with dynamic naming tokens (like @@SERVERNAME, timestamp strings, or database name variables), simplify the naming convention to remove redundant text.
  • Example: Replace long token strings like $(ESCAPE_SQUOTE(JOBID))_$(ESCAPE_SQUOTE(STEPID)) with a simplified static prefix.
  • Re-run the BACKUP command with the shortened device name:
BACKUP DATABASE [CompanyDB] 
TO DISK = N'D:\Backups\CompanyDB.bak' 
WITH NOFORMAT, INIT;

Step 4: Enable Long Path Support (If Required for Deep Directory Structures)

  • On Windows Server 2025 / Windows 11, open Local Group Policy Editor (gpedit.msc).
  • Navigate to Computer Configuration > Administrative Templates > System > Filesystem.
  • Enable “Enable Win32 long paths” and restart the SQL Server service via SQL Server Configuration Manager for the policy to take effect.

Alternative or Verification Steps

  • Verify the fix by re-executing the BACKUP statement with the shortened path; a successful completion message confirms the device name is now within limits.
  • As an alternative, use a SQL Server Backup Device object (sp_addumpdevice) instead of a raw file path—this abstracts the physical path and avoids length issues in the BACKUP command itself.