Identify and change a SQL Server endpoint owner

It is quite common for a DBA or consultant to setup database mirroring or an always on availability group and then leave the organization.
 
When it is time to clean up SQL Server logins on your SQL Server you discover, that although you have revoked access for the login to all databases and server roles, you are still unable to delete the login as it is reported to own an endpoint.
 
Below shows the error reported in SQL Server 2014.
 
image1
 
To confirm the endpoint owner you could use the following:
 

 
image2
 
To change the endpoint owner to sa for an endpoint called Mirroring you would use the following:
 

 
image3
 
Confirm that the endpoint is now owned by sa:
 
image4
 
The legacy DBA or consultant’s login can now be removed from the SQL Server.

Peter

You need to also grant connect on the endpoint or your databases will not synchronize after a fail over. Note this does not need to be done if you use the service account.

GRANT CONNECT ON ENDPOINT::Mirroring TO [sa]

kevin

Thanks Peter, yes once the endpoint owner has been changed it is important to ensure that the remote SQL Server instance can still connect to the endpoint. Generally this is done by granting connect to the remote SQL Server service account i.e.

GRANT CONNECT ON ENDPOINT::Mirroring TO [domain\remote_sql_server_service_account_name];