Make sure the connection is always properly closed