Last active
February 17, 2019 01:48
-
-
Save BrentOzar/0e9692da8ceffeb2b4bdd064e36d3174 to your computer and use it in GitHub Desktop.
Looping through SQL Server trace flags to find the max one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @CurrentTraceFlag INT = 1 | |
/* Hard coding in a max number in case they get wise to this trick and start failing silently */ | |
WHILE @CurrentTraceFlag < 20000 | |
BEGIN | |
BEGIN TRY | |
DBCC TRACEON(@CurrentTraceFlag, -1); | |
DBCC TRACEOFF(@CurrentTraceFlag, -1); | |
END TRY | |
BEGIN CATCH | |
SELECT @CurrentTraceFlag, ERROR_NUMBER(), ERROR_MESSAGE(); | |
BREAK | |
END CATCH | |
SET @CurrentTraceFlag = @CurrentTraceFlag + 1 | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment