Sql-server – Attaching MDF without LDF

sql serversql-server-2005sql-server-2008

I only have an .mdf file of my database which is not attaching.

I am using the following command:

EXEC sp_attach_single_file_db @dbname = 'Test_Data', 
@physname = N'D:\Test_Data\Test_Data.mdf';

and I get the following error message:

Msg 1813, Level 16, State 2, Line 1
Could not open new database 'Test_Data'. CREATE DATABASE is aborted.
Msg 824, Level 24, State 2, Line 1
SQL Server detected a logical consistency-based I/O error: incorrect pageid (expected 1:24; actual 0:0). It occurred during a
read of page (1:24) in database ID 11 at offset 0x00000000030000 in
file 'D:\Test_Data\Test_Data.mdf'. Additional messages in the SQL
Server error log or system event log may provide more detail. This is
a severe error condition that threatens database integrity and must be
corrected immediately. Complete a full database consistency check
(DBCC CHECKDB). This error can be caused by many factors; for more
information, see SQL Server Books Online.

Please help!

Best Answer

Your MDF is actually corrupt, based on that error message. This means you can't attach it.

You could create a database with the same name, substitute MDF (and rename LDF), and hope it comes online or at least suspect to start recovering it.

Otherwise, you'll need to find a 3rd party tool that understands MDF files to get data back.

Or just restore from your latest backup...?