Open and close connection for each operation