How to Attach an MS SQL Database
The Attach feature allows you to deploy a database using raw data (.mdf) and log (.ldf) files. This is an alternative to the Restore method and is useful if you have the direct file structure of your database rather than a .bak backup file.
Important Considerations Before You Begin
- Clean Detach Required: If you plan to attach only a Data file (
.mdf) without a Log file, the database must have been "cleanly" detached from its previous server. This means all transactions must have been committed before the file was copied.
- File Structure Limitations: You can attach exactly one Data file and one Log file (or just one Data file). Databases spread across multiple data files or log files are not supported.
- No Full Text Catalogs: Full text catalogs cannot be deployed via the Attach method. If your database uses Full Text Search, you must use the Backup and Restore method instead.
- Version Compatibility: The internal version of your
.mdf file must be equal to or lower than the MS SQL version of the database created in the control panel.
- Size Limits: The combined size of your files must fit within the storage limits of your assigned hosting plan.
Step-by-Step Instructions
To begin, navigate to the MS SQL section in the control panel, click on your specific database, and select the Attach tab.
Option 1: Upload and Attach
Use this method to upload files directly from your computer. Note that the files will also be saved to the root of your backup location.
- Click the Upload and attach link/button.
- A dialog box will appear. You can browse or drop files to upload.
- Important: If you are uploading both an
.mdf and an .ldf file, you must select or drop both files simultaneously.
- Schema Setting: We recommend keeping the Change default schema to 'dbo' checkbox selected to ensure correct permission mapping.
- Click the button to confirm (labeled Browse and upload... or Attach).
Option 2: Attach from Backup Location
Use this method if your .mdf and .ldf files are already present in your Backup location.
- Click the Attach from backup location link/button.
- In the dialog box, you will see a file browser.
- Select the folder containing your files (usually
root).
- Select the specific
.mdf (and optional .ldf) files you wish to attach.
- Schema Setting: Ensure the Change default schema to 'dbo' checkbox is selected.
- Click the ATTACH button to complete the process.