Retrieving DB from .mdf and .ldf

  • Maybe this topic is already posted before, but i can´t find it.

    It´s possible to recover a db from its physical files? (mdf, ndf's (if any) and ldf)

    Consider this:

    - The dbms is currently up, and the db is working.

    - Can´t be deattached because nobody knows the sa password, and the NT administrator login is disable to access.

    - No backups availables

    TIA

  • You can try this:

    stop SQL service and swap MDF and LDF files to the original database directory. Make sure the filenames match original database setup in order for master database to recognize it. Then restart SQL service.

  • Do you have any user available to execute backups?

  • I guess you need to Rebuild the master database and re-attach all the user databases.

    Shas3

  • pscsvln: are you saying that i must try to recover the db in other server, recovering first the master? If this, remember that i don't have backups availables...

    racosta: No, i don´t have any kind of user.

    Shas3: if i'm not wrong, when you try to rebuild the master, the sa password is asked

  • By rebuilding the master, you can set the appropriate permissions to allow you to attach the databases. Unfortunately you will also need to recreate anything else stored in the master. Logins (both NT and SQL) would need to be recreated, and sometimes there are issues with recreating SQL Logins.

    Since it sounds like you are locked out, however, not sure what choice you have. You could transfer the files to a server to which you have access and reattach them there, but if the logins aren't correct, you may lose some permissions.

    For the future, remember that backing up and testing the master restore should be treated as important as the most mission-critical database on the server. It's an odd restore, so it needs to be practiced from time to time.

  • All you have to do is the following:

    shutdown sqlserver.

    move the current mdf, ndf's and ldf files of the database away, just to be safe.

    copy the old files to the place where the current files where.

    restart sqlserver.

    That works.

    I guess pscsvln meant that the old files should have the same names as those of the current database.

    Joachim

  • RonKyle: Forget about the logins, there is only one that is used by a tool that can be changed. About the 'reattach option', correct me if i´m wrong, you need to previously dettach the db to attach it later...and i haven't access to do it 🙂

    joachim: What you mean when you talk about 'old files'?

  • By the book you do have to detach the databases to be able to reattach them, but so far I have always been able to attach a database even if I haven't first detached it. Won't vouch for every instance, but I have done it several times for testing and a few times in real life with no problem.

  • If you can shutdown the SQL Server for a while, copy the MDF and LDF files and you should be able to attach it.

  • I will try this method, thanks for your help!!!

Viewing 11 posts - 1 through 10 (of 10 total)

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