Add a Database Mirroring Witness Using Windows Authentication (Transact-SQL)

The following example establishes a data mirroring witness.
On the witness server instance (default instance on WITNESSHOST4):

1. Create an endpoint for this server instance for the WITNESS
role only using port 7022.

CREATE ENDPOINT Endpoint_Mirroring
STATE=STARTED
AS TCP (LISTENER_PORT=7022)
FOR DATABASE_MIRRORING (ROLE=WITNESS)
GO

2. Create a login for domain user account of partner instances,
if different; for example, assume that the witness is running
as SOMEDOMAIN\witnessuser, but the partners are running as
MYDOMAIN\dbousername. Create a login for the partners, as follows:

--Create a login for the partner server instances,
--which are both running as MYDOMAIN\dbousername:
USE master ;
GO
CREATE LOGIN [MYDOMAIN\dbousername] FROM WINDOWS ;
GO
--Grant connect permissions on endpoint to login account
--of partners
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [MYDOMAIN\dbousername];
GO

3. On each of the partner server instances, create a login for the
witness server instance:

--Create a login for the witness server instance,
--which is running as SOMEDOMAIN\witnessuser:
USE master ;
GO
CREATE LOGIN [SOMEDOMAIN\witnessuser] FROM WINDOWS ;
GO
--Grant connect permissions on endpoint to login account
--of partners
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [SOMEDOMAIN\witnessuser];
GO

4. On the principal server, set the witness (which is on WITNESSHOST4):

ALTER DATABASE AdventureWorks
SET WITNESS =
'TCP://WITNESSHOST4:7022'
GO

Comments