Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Reinstalled Windows on my development box, forgot to backup any of my work in progress databases in SQL Server Express 2008? Can i recover anything?

I still have the files from the old install. Where do i look?

share|improve this question

The files you are looking for are .ldf and .mdf files.

By default if your database is called foobar you'll have a foobar.mdf file and a foobar_log.ldf file.

You can copy these to your new installation and use sp_attach_db from within SQL management to reattach the files. sp_attach_db was deprecated in SQL 2005, but I believe it still works in SQL 2008.

share|improve this answer
up vote 0 down vote accepted

Thanks goes out to hmallett, for pointing me in the right direction.

I used this to undelete my files. Found them in C:\Program Files\Microsoft SQL Server\MSSQLEXPRESS\DATA. Undeleted my databases to an external fat32 usb drive (to remove the permissions).

Next i opened SQL Server Management Studio and used this to attach it: EXEC sp_attach_db @dbname = N'pickyournewdatabasename', @filename1 = N'F:\TheFolderWhereYouHaveTheRecoveredDB\olddatabasename.mdf' @filename2 = N'F:\TheFolderWhereYouHaveTheRecoveredDB\olddatabasename_log.ldf'

I skipped adding the ldf log file and it generated a new one. You can add it if you want. After this step everything is up and running, you should use normal backup and restore options now.

PS. Make sure you install the same SQL Server version as the old one. If you get the 661 665 error. Go here: SQL Server Version Error. I had R2 install and the Web Platform installed R1 (bug).

share|improve this answer
Dont use this command too often. See here… – unmircea Jul 8 '10 at 17:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.