Standard Single-User Installation: Attach the Microsoft SQL Database

Create users AFM and AFM_SECURE

- /* Create new user called 'afm' */ CREATE LOGIN afm WITH PASSWORD = 'afm', CHECK_POLICY = OFF go /* Create new user called 'afm_secure' */ CREATE LOGIN afm_secure WITH PASSWORD = 'afm', CHECK_POLICY = OFF go

Check these settings

Attach the SQL Database

  1. Copy and paste  hq.mdf file to the location of the DATA folder- (ex: C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLSERVER\MSSQL\DATA)

  2. Open SQL Server Management Studio. In the subsequent dialog, click Connect.

  3. SQL Server Management Studio opens. Open the tree view, right click on Databases, and select “Attach.”

 

  1. The Attach Databases dialog opens:

  1. Click the “Add” button. The “Locate Database Files” dialog opens.

 

  1. The “Attach Databases” dialog opens. Note that the name of the db is listed as “mssql-hq” in the “Attach As” box. Change the name to “hq”

 

  1. As shown below, select mssql-hq_log.ldf and click Remove.

 

  1. Follow the steps in the below image to locate hq.mdf.

 

  1. Click OK, and the following message appears:

 

  1. Click OK on the message. The database is now attached.

  2. In SQL Management Studio, click on “New Query” button:

  1. Select HQ from the drop down window:

 

  1. Paste the following into the editor window:

EXEC sp_addsrvrolemember 'afm_secure','dbcreator' go /* Map the server login of AFM to the database user AFM. */ EXEC sp_change_users_login 'Update_One', 'afm', 'afm' go /* Map the server login of AFM to the database user AFM. */ EXEC sp_change_users_login 'Update_One', 'afm_secure', 'afm_secure' go

 

  1. Click the “Execute” button. Command completed successfully.

 

The HQ database is now ready to go.

enter image description here

Attach the SQL Database: Use a script

Alternatively, you can attach the database from this script:

EXEC sp_attach_db @dbname = N'Hq', @filename1 = N'C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\DATA\Hq.MDF' go