Solved

reading error log through selects

Posted on 2011-09-06
11
357 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

777 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