Solved

reading error log through selects

Posted on 2011-09-06
11
355 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
 
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now