Solved

reading error log through selects

Posted on 2011-09-06
11
354 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
Comment Utility
the where i am interested is in a time period range..
0
 
LVL 2

Expert Comment

by:John_Bon
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Author Comment

by:25112
Comment Utility
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
Comment Utility
couldn't fn_trace_gettable work in our situation?
0
 
LVL 5

Author Comment

by:25112
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
thank you john
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Dynamics crm 2011 8 43
Updating variable table 9 16
Sql query 34 16
BULK INSERT most recent CSV 19 17
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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

772 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

14 Experts available now in Live!

Get 1:1 Help Now