As you have already determined the Hard Drive is not intermittently getting detected, try a few simple troubleshooting steps and check if this fixes the problem:
1. Try a different Hard Drive Data Cable (you can try swapping the cable with the Optical Drive Data Cable).
2. Try to connect the Hard Drive to another power connector from the power supply (SMPS); this will eliminate any power connector related issue.
3. Connect the Hard Drive to a different port on the motherboard. This will eliminate the Hard Drive Port related issue.
4. After performing steps from 1-3 if you determine the port on the motherboard is bad it will require you to replace the motherboard. If the cable is bad replace the cable. If the power supply connector is bad you might want to get your power supply repaired or replaced.
These steps are valid for a desktop computer. If you have a laptop, kindly reply with the exact system model number of your laptop.
Note: Steps 1-3 require you to open the computer chassis. Open the chassis only if you are comfortable, else seek a technician's help. Please remove all power connections and external devices before opening the chassis. Also, press and hold the power button for 10-15 seconds after removing the power connections to release flea power form the system.