adb sometimes won't connect untill after a lot of tries, and sometimes never
I would write this as a comment but I can't. It may be because of the cable. I had this problem with an old cable that kept disconnecting my phone. Even cables that look fine may do this. The problem went away after I bought a new cable.