Attach mdf file

  • I have attached .mdf files successfully to my SQL2000 server from other SQL servers using:

    sp_attach_db @dbname = N'DbName', @filename1 = N'DbFileName'

    where DbName is the new database name;

    DbFileName is the full path of the .mdf file.

    Recently, I have come across a .mdf file that I could not attach to my SQL server using this technique. The message was:

    Server: Msg 5172, Level 16, State 15, Line 1

    The header for file 'D:\DbName\DbFileName.mdf' is not a valid database file header. The FILE SIZE property is incorrect.

    Can anyone help?

  • The file header page (first page in the file) is corrupt - you will not be able to attach this directly. You *might* be able to use the hack method of creating a similar database, shutting the server down, swapping in the corrupt files, and then extracting out the data from the database using emergency mode. I'm not sure if it will work for this particular file header corruption though - as the size is checked when the file is opened.

    Do you have a backup you can use instead? Where did the database come from?

    Thanks

    Paul Randal
    CEO, SQLskills.com: Check out SQLskills online training!
    Blog:www.SQLskills.com/blogs/paul Twitter: @PaulRandal
    SQL MVP, Microsoft RD, Contributing Editor of TechNet Magazine
    Author of DBCC CHECKDB/repair (and other Storage Engine) code of SQL Server 2005

  • I have very little info on the file as we got it off an external client's SQL server. Do I not need some basic info about the source db in order to hack it? Would the corresponding ldf file be helpful?

    Thanks...

    Regards,

  • Just the number of files.

    Thinking about it more - even if you can hack it into the system, the database still won't startup as it will hit the same problem and then shutdown again.

    Unfortunately, I think your client's database is toast.

    Paul Randal
    CEO, SQLskills.com: Check out SQLskills online training!
    Blog:www.SQLskills.com/blogs/paul Twitter: @PaulRandal
    SQL MVP, Microsoft RD, Contributing Editor of TechNet Magazine
    Author of DBCC CHECKDB/repair (and other Storage Engine) code of SQL Server 2005

  • Hi Paul,

    Just a simple one:

    I tried to attach another mdf file to my SQL2000 server and got

    ERROR 602: could not find row in sysindexes for database ID 9, object ID 1, Run DBCC CHeckTABLE on sysindexes.

    I suspect it is a SQL2005 database file.

    Thanks..

  • Yup - looks like it.

    Paul Randal
    CEO, SQLskills.com: Check out SQLskills online training!
    Blog:www.SQLskills.com/blogs/paul Twitter: @PaulRandal
    SQL MVP, Microsoft RD, Contributing Editor of TechNet Magazine
    Author of DBCC CHECKDB/repair (and other Storage Engine) code of SQL Server 2005

  • Why can't you observe it before attaching it. Must remember you should not attach or restore from higher version to lower version like from 2005 to 2000 or from 2000 to 7.0 version.

    Manoj

    MCP, MCTS (GDBA/EDA)

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply