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
-
SQL Server Configuration. Enable TCPIP. Add port 1433 in the IPAll at the end
-
New inbound rule in firewall for port 1433
- Properties\Security: Verify that you have mixed SQL and Windows login
Attach the SQL Database
-
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)
-
Open SQL Server Management Studio. In the subsequent dialog, click Connect.
-
SQL Server Management Studio opens. Open the tree view, right click on Databases, and select “Attach.”
-
The Attach Databases dialog opens:
-
Click the “Add” button. The “Locate Database Files” dialog opens.
- Select the hq.mdg file that you pasted in step 1 and click OK.
-
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”
-
As shown below, select mssql-hq_log.ldf and click Remove.
-
Follow the steps in the below image to locate hq.mdf.
-
Click OK, and the following message appears:
-
Click OK on the message. The database is now attached.
-
In SQL Management Studio, click on “New Query” button:
-
Select HQ from the drop down window:
-
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
-
Click the “Execute” button. Command completed successfully.
The HQ database is now ready to go.
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