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

Troubleshooting Guide: SQL Server Error 5103

Why This Error Happens

This error occurs when attempting to create or modify a database file where the specified MAXSIZE parameter is numerically smaller than the current SIZE parameter, violating SQL Server’s file growth logic. It commonly arises during database restores, file modification scripts (ALTER DATABASE MODIFY FILE), or automated deployment scripts where size values were hardcoded incorrectly or copied from a template without adjustment. SQL Server 2025 strictly validates these constraints before allocating file space on the Windows Server 2025 or Windows 11 file system, rejecting the operation entirely rather than auto-correcting the mismatch.

Step-by-Step Resolution Guide

Step 1: Identify the Conflicting File and Current Values

  • Open SQL Server Management Studio (SSMS) and connect to the target instance.
  • Run the following query to inspect current file sizes (values are in 8KB pages, divide by 128 for MB):
  SELECT name, size, max_size, growth 
  FROM sys.master_files 
  WHERE database_id = DB_ID('YourDatabaseName');
  • Note the logical file name referenced in the error message (%ls).

Step 2: Correct the Script or Command Causing the Error

  • Locate the T-SQL script, PowerShell deployment file, or CI/CD pipeline configuration (e.g., in C:\Scripts\DBDeploy\ or your Azure DevOps YAML) that defines the file properties.
  • Ensure the MAXSIZE value is explicitly greater than the SIZE value, or set it to UNLIMITED:
  ALTER DATABASE [YourDatabaseName] 
  MODIFY FILE (NAME = N'YourFileName', SIZE = 51200KB, MAXSIZE = 102400KB, FILEGROWTH = 10240KB);
  • If unlimited growth is acceptable, use:
  ALTER DATABASE [YourDatabaseName] 
  MODIFY FILE (NAME = N'YourFileName', MAXSIZE = UNLIMITED);

Step 3: Check for Disk Space Constraints on Windows

  • Navigate to the physical drive hosting the .mdf or .ldf file (commonly C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA\).
  • Verify there is sufficient free disk space to support the new MAXSIZE value; low disk space can cause administrators to mistakenly set MAXSIZE too low.
  • Use Windows Server Disk Management or Get-PSDrive in PowerShell to confirm available capacity before increasing the value.

Step 4: Re-run the Database Restore or Creation Script

  • If the error occurred during a restore operation, update the MOVE clause in your RESTORE DATABASE command to match corrected size parameters.
  • Execute the corrected script again:
  RESTORE DATABASE [YourDatabaseName] 
  FROM DISK = N'D:\Backups\YourDatabase.bak' 
  WITH MOVE N'YourFileName' TO N'D:\Data\YourFileName.mdf', 
  REPLACE;

Alternative or Verification Steps

  • Verify the fix by re-querying sys.master_files to confirm max_size is now greater than or equal to size, and check the SQL Server Error Log (ERRORLOG in the MSSQL\Log directory) for successful completion messages.
  • If the error persists in automated pipelines, set MAXSIZE = UNLIMITED as a universal default in deployment templates to prevent future hardcoded mismatches.