# mco_HA_detach_replica

This function detaches (disconnects) the replica identified by the channel pointer.

### For an overview see page HA Applications

### Prototype

        MCO_RET	mco_HA_detach_replica (	mco_db_h db,
                          mco_channel_h chan)

### Arguments

db | Connection handle to master database
chan | A pointer to the channel descriptor (see `mco_HA_get_io_channel()`).

### Description

This function detaches (disconnects) the replica identified by the channel pointer chan. It also performs necessary clean up. On the replica side,``mco_nw_attach_master()`` will return with `stop_reason == MCO_HA_REPLICA_MASTER_REQUESTED_DISCONNECT`.

### Return Codes

MCO_S_OK | Successful.
MCO_E_HA_NOT_INITIALIZED | The HA subsystem has not been initialized – the function `mco_HA_start()` must be called first.
MCO_E_HA_INVCHANNEL | No replica was found with this I/O channel.
MCO_E_HA_IOERROR | The master was unable to send the `DETACH` message to the replica.