In order to perform AdHoc Querying, there is a configuration option that needs to be set. This code checks that setting, changes it if necessary, and restores the change when finished, returning the code to the original environment.