Solved

reading error log through selects

Posted on 2011-09-06
11
362 Views
Last Modified: 2012-05-12
the error log is too big, so i was hoping to use a where clause to cut it short..


SELECT top 10 * FROM fn_trace_gettable('C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\ERRORLOG.1', default);

but I am not able to get the above to work..

is it because it is not a trc file?
0
Comment
Question by:25112
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 5

Author Comment

by:25112
ID: 36492769
the where i am interested is in a time period range..
0
 
LVL 2

Expert Comment

by:John_Bon
ID: 36492905
For ERRORLOG.n

  EXEC sp_readerrorlog n
-- To Read ERRORLOG.1

EXEC sp_readerrorlog 1

Open in new window

0
 
LVL 5

Author Comment

by:25112
ID: 36492909
i want to user where clause and hence select statement.. i need a specific time range only. the file is big so readerrorlog is not an option
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 2

Expert Comment

by:John_Bon
ID: 36492927
The code below will work.
Please see the following link:  http://www.simple-talk.com/sql/database-administration/the-dba-script-thumb/  
CREATE TABLE #TempLog (
      LogDate     DATETIME,
      ProcessInfo NVARCHAR(50),
      [Text] NVARCHAR(MAX))

INSERT INTO #TempLog
      EXEC sp_readerrorlog 1

select top 10 * from #TempLog

Open in new window

0
 
LVL 2

Expert Comment

by:John_Bon
ID: 36492953
Hi,

  Sorry.  Below is a better example using a Where clause for the LogDate and Text fields of the ErrorLog.
CREATE TABLE #TempLog (
      LogDate     DATETIME,
      ProcessInfo NVARCHAR(50),
      [Text] NVARCHAR(MAX))

INSERT INTO #TempLog
      EXEC sp_readerrorlog 

select 
	LogDate
	, ProcessInfo
	, Text
from #TempLog
WHERE 
         LogDate >= '2011-09-01' 
   AND   LogDate < '2011-09-02'
   AND   TEXT LIKE '%Starting up database%'

Open in new window

0
 
LVL 5

Author Comment

by:25112
ID: 36494322
i wish the where can be in the statement

INSERT INTO #TempLog
      EXEC sp_readerrorlog

because right now the log file is too big.. from next time we will plan for this with dbcc errorlog..
0
 
LVL 5

Author Comment

by:25112
ID: 36494358
couldn't fn_trace_gettable work in our situation?
0
 
LVL 5

Author Comment

by:25112
ID: 36499944

INSERT INTO #TempLog
      EXEC sp_readerrorlog
is timing out because of huge # of records.. hence not able to use it..

could sp_readerrorlog  have parameters to filter directly?
0
 
LVL 2

Expert Comment

by:John_Bon
ID: 36500464
The guts of of the sp_readerrorlog are listed below.
Parameters @p3 and @p4 will only filter on the Text field.

http://www.mssqltips.com/sqlservertip/1476/reading-the-sql-server-log-files-using-tsql/

CREATE proc [sys].[sp_readerrorlog](
      @p1            int = 0,
      @p2            int = NULL,
      @p3            nvarchar(4000) = NULL,
      @p4            nvarchar(4000) = NULL)
as
begin

      if (not is_srvrolemember(N'securityadmin') = 1)
      begin
         raiserror(15003,-1,-1, N'securityadmin')
         return (1)
      end
      
      if (@p2 is NULL)
            exec sys.xp_readerrorlog @p1
      else
            exec sys.xp_readerrorlog @p1,@p2,@p3,@p4
end

0
 
LVL 2

Accepted Solution

by:
John_Bon earned 500 total points
ID: 36500486
Alternatively, you may want to use the Log File Viewer to filter the log piecemeal and export to a flat file.  
Then, import the flat files into a database table.
ViewSQLServerLog.png
0
 
LVL 5

Author Comment

by:25112
ID: 36507379
thank you john
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question