Sql-server – Attaching MDF File that appears to have been truncated by the OS

sql serversql-server-2008tsql

I've got an MDF and LDF file from a dead server that I'm trying to attach to another instance of SQL Server. However running the following create database statement

USE [master]
GO
CREATE DATABASE [DBName] ON 
( FILENAME = N'C:\tmp\DBName.mdf' ),
( FILENAME = N'C:\tmp\DBName_log.ldf' )
 FOR ATTACH
GO

Generates this error.

Msg 1813, Level 16, State 2, Line 1
Could not open new database 'DBName'. CREATE DATABASE is aborted.
Msg 5125, Level 24, State 2, Line 1
File 'C:\tmp\DBName.mdf' appears to have been truncated by the operating system.  Expected size is 675840 KB but actual size is 47160 KB.

From reading the MSDN entry I cant see any options on the create database statement that would allow me to ignore this. Is there any other way to force a restoration ignoring the truncation to retrieve some of the data or is the mdf beyond recovery?

Failing that are there any utilities that will allow me to read the contents of the LDF File?

Best Answer

You can create an empty database with the same name and data file names, turn off the SQL service and replace the files with the files from the dead server. Once you bring the SQL service back online it will try to mount the files but more than likely it will come up as suspect and not be readable.