Essentially you want port 5022 for default instance on Server A and Server B.
For named instance you want 5023 for Server A and Server B.
To test which ports are being used, run the following script on each of the instances:
SELECT e.name, e.protocol_desc, e.type_desc, e.role_desc, e.state_desc,
t.port, e.is_encryption_enabled, e.encryption_algorithm_desc,
FROM sys.database_mirroring_endpoints e JOIN sys.tcp_endpoints t
ON e.endpoint_id = t.endpoint_id;
Then drop the incorrect end points (where DBMirrorEndPoint is the name of the endpoint):
IF EXISTS (SELECT * FROM sys.endpoints e WHERE e.name = N'DBMirroringEndPoint')
DROP ENDPOINT DBMirroringEndPoint;
And recreate them using the correct port number (changing the port number as required):
IF NOT EXISTS (SELECT * FROM sys.endpoints e WHERE e.name = N'DBMirroringEndPoint')
CREATE ENDPOINT DBMirroringEndPoint
STATE = STARTED
AS TCP ( LISTENER_PORT = 5022 )
FOR DATABASE_MIRRORING (
AUTHENTICATION = WINDOWS NEGOTIATE,
ENCRYPTION = REQUIRED,
How to manually open Port 5022/tcp in Windows Firewall?
Windows Firewall may block port 5022/tcp by default. If you want to
allow a program to communicate using Port 5022/tcp through the firewall,
you can usually do that by selecting the required program on the
Exceptions tab in Windows Firewall. However, sometimes the program is
not listed in the Exceptions tab. In this case you need to open the port
1.Open Windows Firewall by clicking Start, Control Panel, Security, and then Windows Firewall.
2.Click 'Allow a program through Windows Firewall'.
3.Click 'Add port'.
4.In the 'Name' field, type a friendly name for the port like 'Port-5022/tcp'.
5.In the 'Port number' field, enter the port number '5022/tcp'.
6.Select TCP or UDP, depending on the protocol required for port 5022/tcp.