Generic injectivity and stability of inverse problems for connections