--exclude the witness server for now
--configure the two mirroring partners only
--once the mirroring session is established configure the witness--execute the following script on both mirroring partners
IF NOT EXISTS(SELECT * FROM sys.database_mirroring_endpoints)
BEGIN
CREATE ENDPOINT endpoint_mirroring
STATE = STARTED
AS TCP ( LISTENER_PORT = 5022 )
FOR DATABASE_MIRRORING (
AUTHENTICATION = WINDOWS,
ENCRYPTION = SUPPORTED,
ROLE=ALL);
END
GO
--start the mirroring endpoint
DECLARE @endpoint NVARCHAR(128)
SELECT @endpoint = name
FROM sys.database_mirroring_endpoints
EXEC('ALTER ENDPOINT ' + @endpoint + ' STATE = STARTED')
GO
USE master
GO
IF CAST(SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS NVARCHAR(128)) LIKE '%pc43'
BEGIN
DECLARE @endpoint NVARCHAR(128)
SELECT @endpoint = name
FROM sys.database_mirroring_endpoints
--!!!!!!!!!change the {domainName}
--create a login for the other mirroring partner
CREATE LOGIN [{DomainName}\pc194$] FROM WINDOWS
--!!!!!!!!!change the {domainName}
--grant the other partner's login connect permissions on the mirroring endpoint
EXEC('GRANT CONNECT ON ENDPOINT::' + @endpoint + ' TO [{DomainName}\pc194$]')
END
GO
USE master
GO
IF CAST(SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS NVARCHAR(128)) LIKE '%pc194'
BEGIN
DECLARE @endpoint NVARCHAR(128)
SELECT @endpoint = name
FROM sys.database_mirroring_endpoints
--!!!!!!!!!change the {domainName}
--create a login for the other mirroring partner
CREATE LOGIN [{DomainName}\pc43$] FROM WINDOWS
--!!!!!!!!!change the {domainName}
--grant the other partner's login connect permissions on the mirroring endpoint
EXEC('GRANT CONNECT ON ENDPOINT::' + @endpoint + ' TO [{DomainName}\pc43$]')
END
GO