Implemented the open connection function and close function