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

Troubleshooting Guide: RESTORE Error 4340 in SQL Server 2025

Why This Error Happens

This error occurs when a STOPAT, STOPATMARK, or STOPBEFOREMARK clause (point-in-time restore syntax) is incorrectly applied to a RESTORE DATABASE statement instead of a RESTORE LOG statement. SQL Server 2025 restricts point-in-time recovery options exclusively to transaction log restores because full or differential backups represent a single fixed point in time and cannot be “rolled forward” to an arbitrary timestamp within the backup itself. Essentially, the engine is rejecting the syntax because it only recognizes time-based stopping points when replaying log records, not when restoring static data pages.

Step-by-Step Resolution Guide

Step 1: Identify the Offending T-SQL Statement

  • Open SQL Server Management Studio (SSMS) or Azure Data Studio and locate the exact script generating Error 4340.
  • Check if the WITH clause of your RESTORE DATABASE command includes STOPAT = 'timestamp'.
  • Example of the incorrect syntax:
    RESTORE DATABASE [YourDB] FROM DISK = 'C:\Backup\Full.bak' WITH STOPAT = '2025-01-01 10:00:00';

Step 2: Separate the Restore Sequence

  • Remove the STOPAT clause entirely from the RESTORE DATABASE command for the Full backup.
  • Ensure the Full backup is restored WITH NORECOVERY to allow subsequent logs to be applied.
  • Updated command:
    RESTORE DATABASE [YourDB] FROM DISK = 'C:\Backup\Full.bak' WITH NORECOVERY;

Step 3: Apply the Point-in-Time Clause to the Log Restore

  • Move the STOPAT parameter to the RESTORE LOG statement that follows the full/differential restore.
  • Ensure the log backup file path is correct and accessible via the Windows Server 2025 file system permissions.
  • Correct syntax:
    RESTORE LOG [YourDB] FROM DISK = 'C:\Backup\Log1.trn' WITH STOPAT = '2025-01-01 10:00:00', RECOVERY;

Step 4: Verify Backup Chain Integrity

  • Confirm that the timestamp specified in STOPAT falls within the time range covered by the specific transaction log file being restored.
  • Use RESTORE HEADERONLY on the log file to check the BackupStartDate and BackupFinishDate columns to validate the window.

Alternative or Verification Steps

  • Verification: After running the corrected scripts, query msdb.dbo.restorehistory to confirm the restore_type shows ‘L’ (Log) for the entry containing the stop_at timestamp.
  • Alternative: If you do not need precise time granularity, remove the timestamp entirely and use STOPATMARK = 'mark_name' on the log restore to stop at a specific named transaction instead.