The tail of the log for the database "DBName" has not been backed up

C#SqlSql Server-2005Sharepoint

C# Problem Overview


I tried to restore a database using the following query:

ALTER DATABASE [DatabaseName] SET Single_User WITH Rollback Immediate GO
RESTORE DATABASE DatabaseName FROM DISK = 'C:\DBName-Full Database Backup'
ALTER DATABASE [DatabaseName] SET Multi_User GO

but instead of restoring the database, I am getting this error:

> Msg 3159, Level 16, State 1, Line 2 > > The tail of the log for the > database "DatabaseName" has not been backed up. Use BACKUP LOG WITH NORECOVERY to backup the log if it contains work you do not want to > lose. Use the WITH REPLACE or WITH STOPAT clause of the RESTORE > statement to just overwrite the contents of the log. Msg 3013, Level > 16, State 1, Line 2 RESTORE DATABASE is terminating abnormally.

C# Solutions


Solution 1 - C#

The error message you are getting tells you exactly what you need to do if you don't care about the existing database or log.

RESTORE DATABASE DAtabaseName FROM DISK = 'C:\DBName-Full Database Backup' 
WITH REPLACE

In SQL Server Management Studio (Tasks > Restore), you can add the WITH REPLACE option by opening the page "Options" on the left side and ticking "Overwrite the existing database".

Solution 2 - C#

For those who are using Management Studio this should work:

enter image description here

Solution 3 - C#

Alternatively, you can change the database recovery model to Simple instead of Full.

  1. Right click on the database
  2. Choose properties-> option
  3. Change recovery model to simple

Then what you have written should work without producing errors.

It worked good with me.

Solution 4 - C#

Alternatively, you can change the database recovery model to "Simple" instead of "Full".

Right click on the database, choose 'properties', 'option', change "recovery model" to "simple".

Then what you have written should work without producing errors.

Solution 5 - C#

> Use BACKUP LOG WITH NORECOVERY to backup the log if it contains work > you do not want to lose. > > Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to > just overwrite the contents of the log.

Really, that's the answer. Right there, in the message. What do you want to do? Backup the tail so is no lost? Replace the log that was not backed up? Your call.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontereškoView Question on Stackoverflow
Solution 1 - C#tomfanningView Answer on Stackoverflow
Solution 2 - C#Adil MalikView Answer on Stackoverflow
Solution 3 - C#catcherView Answer on Stackoverflow
Solution 4 - C#saeed khalafinejadView Answer on Stackoverflow
Solution 5 - C#Remus RusanuView Answer on Stackoverflow