Instantly share code, notes, and snippets.

Embed
What would you like to do?
Looping through SQL Server trace flags to find the max one
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