Before you try anything else, restarting your devices may help to solve such connection issue. If you’ve been using your computer and Android phone for a long time, the device may become unresponsive and then your phone won’t detected via USB but still charges.
Connect Android as USB Mass Storage Device Restart Your Devices and Try Another Port