Solved

reading error log through selects

Posted on 2011-09-06
11
359 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

734 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