Add a Database to an Availability Group

  1. Execute the following query against the Anthology Student database. Please follow instructions in the output of the script (error/message).


    DECLARE @DbName NVARCHAR(255) = DB_NAME() , @Cmd NVARCHAR(MAX) = '' SELECT @Cmd = 'Service broker is not enabled on database ('+@DbName+ '). Please make sure that the restore scripts are executed before configuring AG!!' IF (SELECT is_broker_enabled FROM sys.databases WHERE database_id = DB_ID())= 0 RAISERROR(@Cmd, 16, 1) ELSE PRINT 'Service broker is enabled, please proceed with next steps from the AG document!'
  2. Right-click the primary replica and select Add Database. The “Add Database to Availability Group” wizard is displayed.

    Adding a Database

  3. In the wizard, click Select Databases. A list of databases is displayed. Identify the database you want to add to the AG.

    Selecting a Database

  4. In the Status field, click the Password required link. The following message is displayed. Click OK to continue.

    Password Message

    The reason for this message is that the Anthology Student database uses the Service Broker.  As a part of Service Broker configuration, a database master key is set up. A password is required to get past the master key encryption. The master key can be found at the top of the Service Broker configuration script.

  5. In a Query window in SQL Management Studio, open the Service Broker configuration script. Select and copy the encrypted password found near the top of the script.

    Copying the Encrypted Password

  6. In the “Add Database to Availability Group” wizard, right-click the Password required link and paste in the password copied from the Service Broker configuration script.

    Pasting in the Encrypted Password

  7. Click Refresh. The Status field now displays “Meets prerequisites” and the encrypted password appears in the Password field.

    Updating Status and Password

  8. Select the check box next to the database and click Refresh again. The Next button becomes available.

  9. Click Next. The wizard proceeds to the step “Select Data Synchronization”.

    Selecting Data Synchronization

  10. Specify the shared network location that the backups are going to be stored in during the synchronization for the AG. Click Browse.

  11. In the “Connect to Existing Secondary Replicas” step, you will be prompted to specify the shared location for the secondary replica.

    Connecting to Secondary Replica

  12. Click Connect.

    Specifying the Secondary Replica

  13. In our example, secondary replica is CLTSQL2016AGSEC, it has credentials for the secondary replica. Click Connect in the Connect to Server dialog.

  14. The secondary replica is added to the “Add Database to Availability Group” window. Click Next.

    Secondary Replica is Connected

  15. The wizard continues with the “Validation” step.

    Validating the Availability Group

  16. In our example, the validation process returns a warning indicating that there may not be enough disk space.

    Validation Result

  17. When the validation is successful, click Next. The “Summary” screen is displayed.

    Summary Display

  18. Click the drop-down on the Script button and generate a script for the steps of adding a database to the AG. You can the use the script to add a database to the AG instead of the wizard. When you run the script, in case of errors, SQL Management Studio will provide more detailed error messages than the wizard.

    Script Option

    Note that the script must be run in SQLCMD mode.

    Script Message

  19. To run the script in SQL Management Studio menu, select Query > SQLCMD Mode.

    SQLCMD Mode

  20. Execute the script. Depending on the size of the database, this will take multiple hours. The script will take a backup of the existing database at the primary replica and restore it at the secondary replica.

    Executing the Script

  21. When the script is completed successfully, the database is replicated to the AG.

    Script Completed Successfully

  22. In Object Explorer, expand the primary AG folder, navigate to Availability Databases, select the database, right-click, and select Refresh. Our database is now part of the AG.

    Database is Added to Availability Group

  23. In a Query window in SQL Management Studio, open the “CampusVue_<XX.x.x.xxx>_AvailabilityGroup.sql” script from the following folder path

    “C:\Program Files (x86)\CMC\CampusNexus Installation Manager\Packages\Cmc.Installer.Modules.Student.<XX.x.x>\SetupFiles\Database\CampusVue\Other”

    located on the machine where Installation Manager is installed.

    Here <XX.x.x.xxx> represents the Anthology Student version and build number, for example: CampusVue_18.0.0.433_AvailabilityGroup.sql).

    Execute this script on the secondary replica database to create the Anthology Student SQL Server jobs on the secondary replica instance.

    Location of AvailabilityGroup.sql

  24. Similarly, if Regulatory package is selected for installation or upgrade, and a Availability Group script “CampusVue_Regulatory_<XX.x.x.xxx>_AvailabilityGroup.sql” exists in the

    “C:\Program Files (x86)\CMC\CampusNexus Installation Manager\Packages\Cmc.Installer.Modules.Regulatory.<XX.x.x>\SetupFiles\Database\CampusVue\Other”

    folder located on the machine where Installation Manager is installed.

    Here <XX.x.x.xxx> represents the Anthology Student Regulatory version and build number, for example: CampusVue_Regulatory_9.2.0.22_AvailabilityGroup.sql).

    Execute this script on the secondary replica database to create the Anthology Student Regulatory SQL Server jobs on the secondary replica instance.

  25. Execute the script below on the secondary replica of the Anthology Student database if it contains Regulatory version 10.x and above.

    EXECUTE dbo.cmc_CreateJob
    	@JobName = 'Process_FaSSCR_EnrollmentStatusAndDate',
    	@Command = 'Exec dbo.sproc_System_FinancialAid_SSCR_CalculateEnrollments_REG; ',
    	@Desc = 'This job runs once a day at 1:00 AM. Invokes SSCR status and date calculation.',
    	@Sched = 1,
    	@SchedInterval = 'D',
    	@SchedDailyTime = '010000'
    GO
    EXECUTE dbo.cmc_CreateJob
    	@JobName = 'Process_FaStudentAY_LoanPeriod_COA_Recalculate',
    	@Command = 'Exec dbo.Sproc_School_FinancialAid_StudentAY_LoanPeriod_COA_Recalculate_Regulatory; ',
    	@Desc = 'This job runs four times a day. Invokes Cost of Attendance calculation.',
    	@Sched = 1,
    	@SchedInterval = 'H',
    	@SchedDailyTime = '000000',
    	@SchedMinuteInterval = 6
    GO							
    				

This completes the addition of the database to the AG.