If you look at how to temporarily change the sql server settings in order to do a task and when finished revert back? there is a way to save SQL Server settings before enabling them, so you can disable them if needs be.
Here is the code (partially copied):
IF OBJECT_ID('tempdb.dbo.#Settings') IS NOT NULL
DROP TABLE #Settings;
CREATE TABLE #Settings
(
Setting VARCHAR(100),
Val INT
)
INSERT #Settings (Setting, Val)
SELECT 'show advanced options', cast(value_in_use as int) from sys.configurations where name = 'show advanced options'
UNION
SELECT 'xp_cmdshell', cast(value_in_use as int) from sys.configurations where name = 'xp_cmdshell'
UNION
SELECT 'Ad Hoc Distributed Queries', cast(value_in_use as int) from sys.configurations where name = 'Ad Hoc Distributed Queries'
SELECT * FROM #Settings;
That works fine, if you run one procedure at a time; however, it writes to the SQL Server error log as you can see below:
Is there a way to avoid writing changes of settings to the error log?

