open and close connection