Skip to content

How to Restore a DB with Missing Log File Using SQL

by on March 13, 2014

Microsoft SQL Server will sometimes give you an error if the log file is not backed up along with the Database, meaning it is missing from the .bak file.

Error:

System.Data.SqlClient.SqlError: The tail of the log for the database “dbName” 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. (Microsoft.SqlServer.Smo)

 

Solution:

Overwrite the DB, skips the log issue.

In SQL Server > New Query

image

RESTORE DATABASE Mydatabase FROM DISK = ‘F:\mybackupwithoutlogs.bak’ WITH REPLACE

GO

If you are having a problem with users in the DB try:

ALTER DATABASE Mydatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE

GO

RESTORE DATABASE Mydatabase FROM DISK = ‘F:\mybackupwithoutlogs.bak’ WITH REPLACE

GO

Be sure your DB is not left in Single user mode.

Advertisements

From → Microsoft, SQL Server

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: