wrapped the DBAgent instance with a smart pointer surely to free the instance even when an exception is thrown.