If you get the error “This secondary replica is not connected to the primary replica. The connected state is DISCONNECTED”, it means that you are probably using different endpoints on the primary and secondary nodes.
First, you need to see that the endpoints are listening on different ports in alwayson to detect this error.
If they are trying to communicate from different endpoints, you can solve the error by running the following command on both sides.
The following script will drop existing endpoints and create an endpoint listening on the same port. You should first test this process in the test environment. Deleting the endpoint deletion in production environment is a critical process. You must be careful while performing this process.
DROP ENDPOINT [Hadr_endpoint]
CREATE ENDPOINT [Hadr_endpoint]
AS TCP (LISTENER_PORT = 5024, LISTENER_IP = ALL)
FOR DATA_MIRRORING (ROLE = ALL, AUTHENTICATION = WINDOWS NEGOTIATE
, ENCRYPTION = REQUIRED ALGORITHM AES)