Fix SQL Server Error 3117 in 4 Ways
SQL Server error 3117 stops a differential or log restore because the database is not in a restoring state. SQL Server raises the error when an earlier restore used RECOVERY or when no full restore came first.
Four ways fix it. All four restart the restore chain at the full backup with the right recovery option. A decision table shows which way fits your case.
Quick SummaryFix SQL Server error 3117 in four ways. Restore the full backup again with NORECOVERY. Apply the differential backup and then every log backup in order. Use RECOVERY on the last statement only. Use the SSMS Recovery state option if you prefer the wizard. Use STANDBY when users must query the database between restores. Use REPLACE when SQL Server refuses to overwrite a database that is online.
What Does SQL Server Error 3117 Mean?
SQL Server restores a chain of backups in order. The full backup comes first, then the differential backup and then the log backups. The database must remain in the restoring state between the steps.
Error 3117 appears when a step arrives and the database is not in that state. Public reports show the message below, followed by message 3013 that says the restore statement stopped.
Msg 3117, Level 16, State 1, Line 1
The log or differential backup cannot be restored because no files are ready to rollforward.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
Microsoft names RECOVERY as the default option. A RESTORE statement without an option rolls back uncommitted transactions and brings the database online. No differential or log backup applies after that.
Do You Know?Microsoft states that RESTORE needs the NORECOVERY option on every statement except the final one. Microsoft also calls it a best practice to use NORECOVERY on all statements and to finish with a separate RESTORE WITH RECOVERY statement.
Which Fix Matches Your Situation?
| Your situation | Best fix | Data effect |
|---|---|---|
| Full backup restored with default options and the database is online | Method 1 or Method 2 | No loss. The restore restarts at the full backup |
| Full backup never restored on this server | Method 1 | No loss |
| Users must query the database between log restores | Method 3 | No loss. The database remains in a standby state |
| SQL Server refuses to overwrite the existing database | Method 4 | The existing database is deleted |
How Do You Fix Error 3117 With NORECOVERY in T-SQL?
Method 1: Restart the Chain With NORECOVERY
Microsoft lists one prerequisite. Under the full or bulk logged recovery model, take a tail log backup on the source before you restore. The tail contains the work done after the last log backup.
Restore the full backup with NORECOVERY. Then restore the differential backup and every log backup that follows. Finish with RECOVERY.
RESTORE DATABASE SalesDB
FROM DISK = N'D:\Backup\SalesDB_full.bak'
WITH NORECOVERY, STATS = 10;
RESTORE DATABASE SalesDB
FROM DISK = N'D:\Backup\SalesDB_diff.bak'
WITH NORECOVERY, STATS = 10;
RESTORE LOG SalesDB
FROM DISK = N'D:\Backup\SalesDB_log1.trn'
WITH NORECOVERY;
RESTORE DATABASE SalesDB WITH RECOVERY;
Check the state between the steps. The database shows RESTORING until the last statement and ONLINE after it.
SELECT name, state_desc
FROM sys.databases
WHERE name = N'SalesDB';
Microsoft states that a differential restore under the full or bulk logged model returns the database to the point where the differential finished. Apply every log backup taken after that differential to reach the point of failure.
Method 2: Select NORECOVERY in the SSMS Restore Wizard
The wizard sets the same option without T-SQL. Follow the steps from the Microsoft page on restoring a differential backup.
- Right click the database in Object Explorer and select Tasks, then Restore, then Database.
- Select Database as the source for backups in the msdb history or Device for files from another server.
- Tick the full backup and the differential backup that follows it in the Backup sets to restore grid.
- Open the Options page and select Close existing connections if users are signed in.
- Select RESTORE WITH NORECOVERY under Recovery state when more backups follow. Select RESTORE WITH RECOVERY on the last restore and click OK.
Heads UpA restore fails when connections are open on the database. Microsoft also states that RESTORE cannot execute inside an explicit or implicit transaction.
Method 3: Restore With STANDBY for Query Access
STANDBY opens the database for queries between log restores. Microsoft states that the standby file brings the database up for query access between transaction log restores.
RESTORE DATABASE SalesDB
FROM DISK = N'D:\Backup\SalesDB_full.bak'
WITH STANDBY = N'D:\Backup\SalesDB_undo.stn';
RESTORE LOG SalesDB
FROM DISK = N'D:\Backup\SalesDB_log1.trn'
WITH STANDBY = N'D:\Backup\SalesDB_undo.stn';
The next RESTORE statement deletes the undo file by itself. Microsoft warns that a standby file deleted by hand before the next restore forces a full restore of the entire database again.
Free disk space matters too. The restore stops when the disk that contains the standby file has no free space.
Method 4: Overwrite an Online Database With REPLACE
SQL Server refuses a restore in two cases. The first case is a database name that differs from the name in the backup set. The second case is an old file that SQL Server cannot match to this database.
REPLACE removes both checks. Close the connections first and restore the full backup with NORECOVERY.
ALTER DATABASE SalesDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
RESTORE DATABASE SalesDB
FROM DISK = N'D:\Backup\SalesDB_full.bak'
WITH REPLACE, NORECOVERY;
Heads UpMicrosoft states that REPLACE deletes the existing database and overrides the rule that requires a tail log backup. Take a tail log backup yourself when the old database contains work that no backup has.
Why Does the Database Wait in Restoring State?
The opposite problem appears when you forget the last statement. The database waits in RESTORING and no user can open it.
Execute RESTORE DATABASE with RECOVERY to bring it online. The post on a SQL database stuck in restoring state shows the checks. The post on restoring a database with NORECOVERY explains the option in more detail.
A restore from a newer server to an older server returns a different error. Follow SQL Server error 3169 for that case. The guide on backup and restore strategy for SQL Server shows how to plan the chain so the full, differential and log backups match.
Common Questions on Error 3117
What Does RESTORE WITH RECOVERY Do in SQL Server?
It rolls back uncommitted transactions and brings the database online. SQL Server accepts no more differential or log restores for that sequence after it. RECOVERY is the default when you set no option.
Can You Restore a Differential Backup After the Database Is Online?
No. Restore the full backup again with NORECOVERY and apply the differential backup after it. Microsoft names NORECOVERY as the option for every statement before the last.
How Do You Query a Database Between Log Restores?
Restore with STANDBY. Microsoft states that the standby file brings the database up for query access between transaction log restores.
Does Error 3117 Mean the Backup File Is Damaged?
No. Error 3117 names the restore state and not the file. Execute RESTORE VERIFYONLY with CHECKSUM to test a file that you doubt.
How Do You Reach the Point of Failure After a Differential Restore?
Apply every log backup taken after the last differential backup. The differential alone returns the database to the point where the differential finished.
Who, How and WhyAndrew Jackson, Technical Content Specialist, is the author of this guide. The recovery options, the NORECOVERY rule, the STANDBY limits and the REPLACE rule follow the Microsoft page for RESTORE arguments. The SSMS steps, the tail log prerequisite and the point of failure note follow the Microsoft page on restoring a differential backup. The T-SQL was checked for syntax against Microsoft documentation and was not executed on a live server. The message text of error 3117 comes from public reports because the Microsoft pages used here do not quote it. The guide exists because error 3117 sends people to repair a backup file that has no fault.
Key Takeaways
- SQL Server error 3117 means the database is not in a restoring state when a differential or log backup arrives.
- RECOVERY is the default option. A restore without an option closes the chain.
- NORECOVERY on every statement except the last makes the next restore possible.
- STANDBY gives query access between log restores and needs its undo file to remain in place.
- REPLACE deletes the existing database and overrides the tail log rule. Take a tail log backup first.