SQL Server Transactional Replication
SQL Server Transactional Replication
This document and the information controlled therein is the property of Click Studios. It must not be reproduced in whole/part, or
otherwise disclosed, without prior consent in writing from Click Studios.
Click Studios
Table of Contents
1 OVERVIEW .............................................................................................................................. 3
2 PREREQUISITES ....................................................................................................................... 4
3 CONFIGURING THE DISTRIBUTION DATABASE ....................................................................... 9
4 CREATING THE PUBLISHER .................................................................................................... 17
5 CREATING THE SUBSCRIBER.................................................................................................. 24
6 CONNECT PASSWORDSTATE TO YOUR REPLICATED DATABASE ........................................... 34
7 TRANSACTIONAL REPLICATION CONSIDERATIONS ............................................................... 36
8 HOW TO TROUBLESHOOT TRANSACTION REPLICATION....................................................... 37
Click Studios
1 Overview
This document will provide instructions for configuring SQL Server Transactional Replication for High
Availability of the Passwordstate Database.
These instructions are created using SQL Server 2019 Standard edition and are intended as a guide only. If
you have any technical issues with SQL Server, please contact Microsoft for support
Note: When using the High Availability module of Passwordstate, your distribution and publication
databases must reside on SQL Server 2012, 2014, 2016, 2017 or 2019 Standard or above – SQL Express can
only act as a subscriber to SQL Server replication. You must also be using the same version of SQL Server for
both database servers.
Below is some information about a test environment used to document this process, to help you
understand our instructions easier:
tranweb01.halox.net
• Role – Passwordstate primary web server
• Microsoft Windows 2019 Server OS
• Primary Passwordstate website installed and is connected SQL on transql.halox.net
transql01.halox.net
• Role – Passwordstate primary database Server
• Microsoft Windows 2019 Server OS
• Microsoft SQL Standard 2019
• Hosts a Passwordstate database with data stored in this database from several months of using
Passwordstate in a non-high availability configuration.
tranweb02.halox.net
• Role - Passwordstate secondary web server
• Microsoft Windows 2019 Server OS
• Has HA instance of Passwordstate installed, but not yet connected to a database. Instructions for
HA Install located here:
https://www.clickstudios.com.au/downloads/version8/High_Availability_Installation_Instructions.
pdf
transql02.halox.net
• Role – Passwordstate secondary database Server
• Microsoft Windows 2019 Server OS
• Microsoft SQL Server Express 2019
Domain account:
• halox\sqlha
• Is a member of the Domain Users group only
2 Prerequisites
1. This process assumes you have a working install of Passwordstate, connected to a database called
Passwordstate, running on an instance of SQL Server Standard or above.
2. Prior to starting this process, you should ensure that you have the SQL Server Replication feature
installed on both your primary, and secondary database servers. You can install this by running
your SQL Server installation, and selecting the following options:
• Select New SQL Server stand-alone installation or add new features to an existing installation
• Select Add features to an existing instance of SQL Server, and select the appropriate instance
!
Click Studios
• Select the SQL Server Replication feature if it isn’t already selected, and then run through the
rest of the process to finish the installation
3. You will need a domain account with Domain User rights. For this process we have created an
account called halox\sqlha in Active directory.
• Add this account into both SQL Servers using SQL Management Studios Tools by expanding
Security -> Logins and selecting New Login
Click Studios
• Enter your domain account in the format of domain\username and click Check Names, and
then click OK
Click Studios
• Finally, click OK
Ensure you repeat this process for your second database server, and then proceed to the next step.
Click Studios
4. Later in this process you will need to specify a folder for the Transaction Replication snapshots to
be stored in. Microsoft require this folder to be local to the Database server, and not a shared UNC
path, even if it’s a mapped drive to a shared UNC path.
If you have a second disk in your server, like a D drive for example, then it is preferred that you use
this drive. For this documentation, we are using the C drive.
You will need to grant your domain account (halox\sqlha) Modify rights to this folder on your
primary SQL Server. In this case the default folder in the wizard and the one we’ll use is
C:\Data\repldata
Click Studios
First, we need to configure the SQL Server Agent to start automatically. This service is what sends
replication data to the remote SQL server. Follow these steps below to set the service correctly:
• Open SQL Server Configuration Manager on your primary database server, and go to the
properties of the SQL Server Agent service and choose Automatic for the Start Mode property:
• Now we’ll configure the Distribution Database. Using SQL Management Studio Tools, right click
Replication and select Configure Distribution
• Select Next
Click Studios
• On the Snapshot Folder screen, it is preferable to enter another disk on the server to store these
snapshots. Don’t use a UNC path to a network share, or map a drive letter to a UNC path for this
screen. Change the path to the folder you created earlier in this process, (C:\Data\repldata), and
click Next
Click Studios
• On the Distribution Database page, change the paths for the database file and the log file to your
snapshot folder, and click Next
• Click Finish
Click Studios
• The Distributor will now be configured, and when finished it will show “Success”. You can now click
Close:
• Under System Databases, ensure the Distribution Database has been successfully created
Click Studios
• Expand Security -> Logins and select Properties for the domain account which will be used for
replication, in this case it is halox\sqlha
• Select User Mapping, tick the Passwordstate database, and enable db_owner rights
Click Studios
• Next, tick the Distribution database, select db_owner rights, and click OK
Click Studios
• Tick the Tables checkbox, and then select the Set Properties of All Table Articles
• Set the following options to True if not already set, and click OK, and then click Next
o Copy foreign key constraints
o Copy check constraints
o Copy clustered index
o Copy nonclustered indexes
o Copy default value specifications
o Copy extended properties
o Copy unique key constraints
Click Studios
• Click Security Settings button and set you domain account in the format of domain\username, and
apply the correct password, and click OK
Click Studios
• Click Next
• Give the Publication a relevant name, such as Passwordstate_Publication, and click Finish
• In SQL Server Management Studio, ensure you are connected to transql01, right click
Passwordstate_Publication and select New Subscriptions
• Ensure you have transql01 selected as the Publisher, and also the Passwordstate_Publication, and
click Next
• Type in the name of your second database server, (transql02\sqlexpress), that you’ll be replicating
data to. By default, it will try to use the currently logged in user, (halox\lsand), to establish the
connection. If this account does not have permissions in SQL on transql02, you’ll either need to
grant it permissions or use another account that does, such as the local SA account for transql02
server.
Ensure you include the instance name on this remote server if appropriate:
Click Studios
• Set the database name to be passwordstate, and then click the button to set an Owner of the
database
Click Studios
• Click the Browse button and select the halox\sqlha account and click OK
• Click OK
Click Studios
• Click Next
• Set you domain account in the format of domain\username, and apply the correct password, and
click OK
• Click Next
Click Studios
• Click Finish
Click Studios
Note: If creating the subscriber fails at this point, and you are using SQL Server 2019, this may be caused by
a bug in SQL. Please see Section 7: How to troubleshoot Transaction Replication for a fix for this issue.
Click Studios
Prior to installing your second website using the instructions above, you’ll need to add your
passwordstate_user SQL account into your second database instance.
• Open SQL Management Studio Tools and connect to your second database server, and under
Security -> Logins, select New Login:
Click Studios
• Ensure you select SQL Server Authentication, and set your name for the account and a
password. Note these details will be used during the initial install of your High Availability
server:
• Now you need to give this new account db_owner rights to the Passwordstate database:
Click Studios
GO
EXEC sp_configure 'show advanced options', 1 ;
RECONFIGURE ;
GO
EXEC sp_configure 'max text repl size', -1 ;
GO
RECONFIGURE;
GO
Click Studios
USE Passwordstate
SELECT COUNT(*) FROM Auditing
• Check your snapshot folder for any files. If there are no files then replication is not working. Check
all permissions are set correctly, and possibly reinitialize the replication
Click Studios
%SystemRoot%\SysWOW64\
%SystemRoot%\SysWOW64\1033