The settings for “show advanced options” are only necessary if the setting that you want to change is an advanced option.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
-- declare and set variables to initial settings DECLARE @show BIT, @OLE BIT; SELECT @show = CONVERT(BIT, value_in_use) FROM sys.configurations WHERE name = 'show advanced options'; SELECT @OLE = CONVERT(BIT, value_in_use) FROM sys.configurations WHERE name = 'Ole Automation Procedures'; -- set the settings to how needed IF @OLE = 0 BEGIN IF @show = 0 BEGIN EXECUTE sp_configure 'show advanced options', 1; RECONFIGURE WITH OVERRIDE; END; EXECUTE sp_configure 'Ole Automation Procedures', 1; RECONFIGURE WITH OVERRIDE; END; -- do your magic using these settings -- restore the settings to their initial configuration IF @OLE = 0 BEGIN EXECUTE sp_configure 'Ole Automation Procedures', 0; RECONFIGURE WITH OVERRIDE; END; IF @show = 0 BEGIN EXECUTE sp_configure 'show advanced options', 0; RECONFIGURE WITH OVERRIDE; END; |