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

Troubleshooting Guide: SQL Server Error 5034

Why This Error Happens

Error 5034 occurs when a database file is locked by an internal SQL Server operation—typically an autogrow event, DBCC SHRINKFILE, or another file-modification task—at the exact moment another process attempts to access or modify that same file. This is a concurrency conflict rather than a corruption issue: SQL Server enforces a file-level lock during autogrow/autoshrink operations to maintain data integrity, and overlapping requests (such as a second growth event or a concurrent backup) are rejected until the lock is released. It is often exacerbated by small autogrowth increments, which cause the file to grow frequently and increase the window for collision.

Step-by-Step Resolution Guide

Step 1: Identify the Conflicting Process

  • Query sys.dm_exec_requests and sys.dm_os_waiting_tasks to check for active DBCC SHRINKFILE, ALTER DATABASE MODIFY FILE, or autogrow operations running against the affected database.
  • Check the SQL Server Error Log (via SSMS > Management > SQL Server Logs, or C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG) for recent “Autogrow” entries timestamped near the error.
  • Run SELECT name, physical_name, growth, is_percent_growth FROM sys.master_files WHERE database_id = DB_ID('YourDB'); to confirm current growth settings.

Step 2: Adjust Autogrowth Settings to Reduce Collision Frequency

  • Open SSMS, right-click the database > Properties > Files, and change autogrowth from a percentage-based value to a fixed MB increment (e.g., 256MB or 512MB) to reduce how often growth events trigger.
  • Alternatively, run: ALTER DATABASE [YourDB] MODIFY FILE (NAME = 'YourDB_Data', FILEGROWTH = 256MB);
  • Pre-size the data and log files to their expected production size using ALTER DATABASE ... MODIFY FILE (SIZE = ...) to minimize future autogrow events entirely.

Step 3: Enable Instant File Initialization (IFI)

  • On Windows Server 2025/Windows 11, grant the SQL Server service account the “Perform Volume Maintenance Tasks” permission via secpol.msc > Local Policies > User Rights Assignment.
  • Restart the SQL Server service (via SQL Server Configuration Manager) for the policy change to take effect.
  • Verify IFI is active by checking the Error Log for the message “Database Instant File Initialization: enabled” after restart; this drastically shortens the autogrow lock window for data files (note: log files cannot use IFI).

Step 4: Retry the Operation and Avoid Overlapping Maintenance Jobs

  • Reschedule any overlapping SQL Agent jobs (backups, index maintenance, shrink operations) so they don’t run concurrently with periods of high transactional growth.
  • Re-run the failed query, backup, or application transaction after confirming no blocking session remains in sys.dm_exec_requests.

Alternative or Verification Steps

  • Verify the fix: Monitor sys.dm_os_performance_counters for the “Auto-Grow” counter or re-check the Error Log over 24–48 hours to confirm autogrow events no longer overlap with failed operations.
  • Alternative: If frequent growth is unavoidable due to workload volatility, manually pre-allocate file sizes during a maintenance window and disable autogrowth entirely (FILEGROWTH = 0), pairing this with proactive disk space monitoring/alerts.