Friday, June 19, 2015

query sql error log

Grab the information of sql error log in a table and query


--gather all the error in a temp table and query the temp table to find the specific error by text search or date range

CREATE TABLE #SQLErrorLog



(
 
LogDate DATETIME,

ProcessInfo VARCHAR(50),

Text VARCHAR(1500)



)
 
GO
 
INSERT INTO #SQLErrorLog

EXEC xp_readerrorlog 0



go
 
INSERT INTO #SQLErrorLog

EXEC xp_readerrorlog 1



go
 
INSERT INTO #SQLErrorLog

EXEC xp_readerrorlog 2



go
 
INSERT INTO #SQLErrorLog

EXEC xp_readerrorlog 3



go
 
INSERT INTO #SQLErrorLog

EXEC xp_readerrorlog 4



go
 
INSERT INTO #SQLErrorLog

EXEC xp_readerrorlog 5



go


 
SELECT * FROM #SQLErrorLog

WHERE LogDate >= CONVERT(datetime,'06/08/2015') AND LogDate < CONVERT(datetime,'06/20/2015')

and Text LIKE '%failed%' OR Text LIKE 'Error:%'

ORDER BY LogDate DESC

DROP TABLE #SQLErrorLog

No comments:

Post a Comment