Hello, I am Pete, and I'll be happy to assist with your question today.
If the connection only works occasionally, then this is a sign that there is a bad connection between the camera and the computer.
Possible causes of this are:
1. Worn connector on the computer (least likely)
2. Worn connector on the camera (unlikely)
3. Worn connections on the cable ends (most likely)
Over time, the connections will gradually wear out and may not connect all of the conductors successfully.
Try replacing the cable first. If that does not help, then try connecting the camera to a different computer to help determine if the problem is with the computer or the camera itself.