Holding a sailboat on a compass heading basically doesn't work. On any typical area of water, the wind direction changes at various points depending on the surroundings. Trying to hold a set compass heading without knowing the wind direction where the boat is simply doesn't work, or is unlikely to work unless there is a very cleverly programmed computer on board.
With free sailing boats, there are various methods of having the boat hold to a heading on the wind - weighted rudder, Braine, vane are some.