Sunday, December 19, 2010

How to Attach Database in SQL SERVER

This is a step by step walkthrough to attach the Database in SQL SERRVER, if you have data file (.mdf) only and you don’t have log file (.ldf)
I had tried to simplify the steps with the help of screen shots

Connect to your SQL SERVER enterprise manager, in my case I have connected to SQL SERVER 2011 “Denali”
Right click on the Databases, a menu will appear,

Click on Attach, a form Attach Databases will appear

Click on the Add button, file open dialog will appear to select the required file.

Locate your desired data file (.mdf) from your system, and then select that file and then click OK
You will be back again on the Attach Databases dialog, showing the file you have selected. I have selected the AdventureWorks data file.

You can see the row, I highlighted, this is because, I am going to attach the data file with the log file. If you have the log file, then you wouldn’t the message “Not Found”
You can see that currently Remove button is disabled, click on the Row showing the log file

After clicking the Row, Remove button will be enabled, and then click on the Remove button
The Row containing the log file will be removed. If you don’t remove the row containing the log file, the Database wouldn’t be attached, and it will give the error “An error occurred while attaching the Database”.
Click on OK button, the database will be attached successfully.

1 comment:

  1. Its not working... I am still getting the error --
    "An error occurred while attaching the Database"

    Kindly suggest any solutions.


Share This