Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

ERROR LOG (Monitering Scripts) Expand / Collapse
Author
Message
Posted Wednesday, April 29, 2009 6:21 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, May 17, 2013 7:30 AM
Points: 39, Visits: 471
Hi All,

Can some one help me in building a Simple SQL scripts which can be used to moniter the Error Log (Sql server)
As my monitering Tool does not read Stored Procredure.(its the drawback).

I we have the Script, i can be used to ping the Server and any issues found then alert ..

Many Thanks,
Gagan,
Post #706716
Posted Wednesday, April 29, 2009 6:53 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, May 17, 2013 4:52 AM
Points: 1,397, Visits: 2,738
If you want to filter the result set SET @ Filter = 'Whatever you want to filter by'

DECLARE @filter VARCHAR(100), @LogDate DATETIME

SET @LogDate = getdate()

SET NOCOUNT ON

set transaction isolation level read uncommitted
set lock_timeout 10000


BEGIN

IF EXISTS (SELECT * FROM tempdb..sysobjects
WHERE id = object_id(N'[tempdb]..[#TempLog1]'))
DROP TABLE #TempLog1

CREATE TABLE #TempLog1
(LogDate datetime, ProcessInfo varchar(50),ErrorLog VARCHAR (1000))

INSERT INTO #TempLog1
EXEC('xp_readerrorlog')

IF @filter IS NULL AND @LogDate IS NULL
BEGIN
SELECT LogDate, ErrorLog
FROM #TempLog1
ORDER BY LogDate DESC
END
ELSE IF @filter IS NOT NULL AND @LogDate IS NULL
BEGIN
SELECT LogDate, ErrorLog
FROM #TempLog1
WHERE ErrorLog Like '%'+@filter+'%'
ORDER BY LogDate DESC
END
ELSE IF @filter IS NULL AND @LogDate IS NOT NULL
BEGIN
SELECT LogDate, ErrorLog
FROM #TempLog1
WHERE LogDate BETWEEN CONVERT(VARCHAR(50), CAST(@LogDate AS DATETIME), 101)
AND CONVERT(VARCHAR(50), CAST(@LogDate + 1 AS DATETIME), 101)
ORDER BY LogDate DESC
END
ELSE --Both parameters have values
BEGIN
SELECT LogDate, ErrorLog
FROM #TempLog1
WHERE LogDate BETWEEN CONVERT(VARCHAR(50), CAST(@LogDate AS DATETIME), 101)
AND CONVERT(VARCHAR(50), CAST(@LogDate + 1 AS DATETIME), 101)
AND ErrorLog Like '%'+@filter+'%'
ORDER BY LogDate DESC
END
END

DROP TABLE #TempLog1



Facts are stubborn things, but statistics are more pliable - Mark Twain
Carolyn
SQLServerSpecialists
Post #706753
Posted Wednesday, April 29, 2009 10:26 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, May 17, 2013 8:51 AM
Points: 2,100, Visits: 1,789
Please don't post the same question multiple times. See http://www.sqlservercentral.com/Forums/Topic706719-146-1.aspx



Francis
Post #707031
Posted Wednesday, April 29, 2009 10:34 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 9:03 PM
Points: 31,406, Visits: 13,723
Closing this thread.






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #707037
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse