Error-checked connection method.