This topic describes how to attach a database using dbForge Studio for SQL Server.
You can also use this feature as part of the process to copy, move, or upgrade a SQL Server database.
Attaching a database directly from a newer version of SQL Server to an older version may fail or cause compatibility errors. For example, files detached from SQL Server 2022 can’t be attached to SQL Server 2017. Attempting to do so will result in the following error:
An error occurred while attaching the database. The database < database_name > cannot be opened
because it is version < version_number >. This server supports version < version_number > and earlier.
A downgrade path is not supported. Could not open new database < database_name >. CREATE DATABASE is aborted.
Since a direct downgrade isn’t possible, you can use an alternative way to transfer data from 2022 to 2017:
1. Attach the database detached from SQL Server 2022 to any available SQL Server 2022.
2. Create an empty database on SQL Server 2017.
3. Copy the schema and data from the database on SQL Server 2022 to the database on SQL Server 2017 using the Schema and Data Compare features of dbForge Studio.
4. Verify that the database on SQL Server 2017 contains all required data.
5. Detach the original database from the SQL Server 2022.
You must be a member of the sysadmin or db_owner role.
sys.database_files system catalog view before detaching it from the existing SQL Server instance:SELECT type_desc, name, physical_name
FROM sys.database_files;
where:
type_desc – The description of the file type: ROWS, LOG, FILESTREAM, and FULLTEXT.name – The logical name of the file in the database.physical_name – The operating-system file name.1. Connect to a server instance.
2. Open the Attach Database dialog in one of these ways:
3. In the Browse Files dialog, choose the .mdf file of the required database, then click OK.
Warning
An attempt to select an already-attached database fails. The following error message appears:
CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Program Files\Microsoft SQL Server\MSSQLxx.MSSQLSERVER\MSSQL\DATA\database_name.mdf'.

4. To add multiple .mdf files:
4.1. In the Attach Database dialog, click Add.
4.2. In the Browse Files dialog, select the .mdf file for the database, then click OK.
4.3. Repeat these steps for each file you want to add.

5. To rename the database, double-click its name in Attach As and enter a new name.
Tip
To remove the file from the grid in the Attach Database dialog, select it, then click Remove.
6. Click OK to attach the database.
After the database is attached, it gets the
icon in the Status column.
7. Click Close to close the dialog.

You can attach a database to an instance of SQL Server by using the CREATE DATABASE ... FOR ATTACH statement.
To attach a database by using CREATE DATABASE ... FOR ATTACH:
1. On the SQL toolbar, click New SQL to open a new SQL document.
2. Attach the database. Replace the arguments with your actual database name and file paths.
CREATE DATABASE database_name
ON (FILENAME = 'path_to_file.mdf'),
(FILENAME = 'path_to_file.ldf')
FOR ATTACH;
where:
database_name – The name of the database you want to attach.'path_to_file.mdf' – The full path to the primary data file (.mdf).'path_to_file.ldf' – The full path to the transaction log file (.ldf).