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

Troubleshooting Guide: SQL Server Error 1501 – Sort Failure

Why This Error Happens

Error 1501 typically occurs when SQL Server 2025 encounters insufficient space in tempdb or the designated sort workspace while performing a sort operation, often during index creation, rebuilding, or complex query execution. This can also stem from corrupted temporary files, disk I/O errors on the volume hosting tempdb, or memory pressure that prevents SQL Server from allocating sufficient workspace for the sort buffer. In some cases, file system permission issues on the tempdb data/log files in Windows Server 2025 / Windows 11 environments can trigger this failure as well.

Step-by-Step Resolution Guide

Step 1: Verify Tempdb Disk Space and Health

  • Open Disk Management or run Get-PSDrive in PowerShell to confirm free space on the drive hosting tempdb (commonly C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA).
  • Ensure at least 20-25% free space is available; sort operations require significant temporary workspace.
  • Run CHKDSK C: /F /R (replace C: with your actual tempdb drive) during a maintenance window to rule out disk corruption.

Step 2: Increase or Reconfigure Tempdb Files

  • Open SQL Server Management Studio (SSMS) and connect to the instance.
  • Execute the following to check current tempdb configuration:
  SELECT name, size/128 AS SizeMB, physical_name 
  FROM tempdb.sys.database_files;
  • Increase the initial size and set appropriate autogrowth (e.g., 10% or fixed MB increments) using:
  ALTER DATABASE tempdb MODIFY FILE (NAME = tempdev, SIZE = 5120MB, FILEGROWTH = 512MB);
  • Consider adding multiple tempdb data files (one per CPU core, up to 8) to reduce contention.

Step 3: Check and Repair File Permissions

  • Navigate to the tempdb file directory in File Explorer.
  • Right-click the folder, select Properties > Security, and confirm the SQL Server service account (e.g., NT Service\MSSQLSERVER) has Full Control.
  • If permissions are missing, click Edit > Add, enter the service account name, and grant Full Control.

Step 4: Restart SQL Server Service and Monitor Logs

  • Open Services.msc, locate SQL Server (MSSQLSERVER), and restart it.
  • Simultaneously, open SQL Server Error Log via SSMS (Management > SQL Server Logs) to confirm tempdb initializes without errors.
  • Re-run the failed sort operation (query, index rebuild, etc.) to test for recurrence.

Step 5: Clear Corrupted Temporary Files (If Applicable)

  • Stop the SQL Server service via Services.msc.
  • Manually delete any orphaned .tmp files in the tempdb directory (only if SQL Server is fully stopped).
  • Restart the SQL Server service to regenerate clean tempdb files.

Alternative or Verification Steps

  • Run DBCC CHECKDB('tempdb') after restarting the service to confirm database integrity and absence of corruption.
  • If the error persists, move tempdb to a dedicated high-speed SSD volume with ample free space using ALTER DATABASE tempdb MODIFY FILE with a new FILENAME path, then restart the SQL Server service to apply changes.