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
MAXSIZEvalue is explicitly greater than theSIZEvalue, or set it toUNLIMITED:
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
.mdfor.ldffile (commonlyC:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA\). - Verify there is sufficient free disk space to support the new
MAXSIZEvalue; low disk space can cause administrators to mistakenly setMAXSIZEtoo low. - Use Windows Server Disk Management or
Get-PSDrivein 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
MOVEclause in yourRESTORE DATABASEcommand 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_filesto confirmmax_sizeis now greater than or equal tosize, and check the SQL Server Error Log (ERRORLOGin theMSSQL\Logdirectory) for successful completion messages. - If the error persists in automated pipelines, set
MAXSIZE = UNLIMITEDas a universal default in deployment templates to prevent future hardcoded mismatches.