Query your SQL Server ERRORLOGS

Quick post in response to a number of Twitter and Forum questions I’ve seen lately.

Downloadable from the Microsoft code Gallery (with ranking options!)

“How can I search my SQL ERRORLOGS with native tools?”

Create Table #Errorlog 
	(Logdate datetime, 
	 ProcessInfo varchar(50), 
	 LogText varchar(5000))

--Dump all the things into the table
insert into #Errorlog
EXEC sys.xp_readerrorlog 
	0			-- Current ERRORLOG
	,1			-- SQL ERRORLOG (not Agent)

--Query just like you would anything else:
Select * 
from #Errorlog 
Where 1=1
	--and LogText like '(c) Microsoft Corporation%'
	and (LogText like '%Error%'	or LogText like '%Fail%'--or LogText like '%SPN%'
	And Logdate > getdate() -1
	And LogText Not Like '%CheckDB%'
	And LogText not like '%35262%'
	And LogText not like '%35250%'

--Clean up your mess, you weren't raised in a barn!
Drop Table #Errorlog

I run this every morning against my Prod Local Server Group in SSMS Registered Servers

Leave a Comment

Sign up for our Newsletter

%d bloggers like this: