Orphaned MDF file

  • Hi all,

    Been asked to restore an orphaned MDF file leftover after a botched uninstall - no .bak file. Tried to reattach, but got an error, I don't think it had been detached. My initial answer was, "No, very likely can't be done".

    Am I right? Or is there a way of attaching it that doesn't require it to have been detached?

    Cheers,

    Jake.

  • What was the error that was generated?

    You can attach a .MDF file using sp_attach_single_file_db:- http://msdn.microsoft.com/en-us/library/ms174385.aspx but it does require that the database was shutdown in a controlled fashion.

  • You can attach the database using CREATE DATABASE FOR ATTACH_REBUILD_LOG.

    http://msdn.microsoft.com/en-us/library/ms176061.aspx

    If that doesn't work, you can try the undocumented FOR ATTACH_FORCE_REBUILD_LOG.

    CREATE DATABASE <YOURDBNAME>

    ON (FILENAME = 'D:\<YOURMDFNAME>.mdf')

    FOR ATTACH_FORCE_REBUILD_LOG

  • Intriguing, will try it out guys and let you know 🙂

  • Fellas, it worked, passing you a big thank you from my management, who dragged me out for a few free beers as a result!!!

Viewing 5 posts - 1 through 4 (of 4 total)

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