Skip to content

Latest commit

 

History

History
97 lines (76 loc) · 4.67 KB

File metadata and controls

97 lines (76 loc) · 4.67 KB
title SqlErrorLogEvent Class
ms.custom
ms.date 03/14/2017
ms.prod sql
ms.prod_service database-engine
ms.reviewer
ms.technology wmi
ms.topic reference
helpviewer_keywords
SqlErrorLogEvent class
SqlErrorLogFile class
ms.assetid bde6c467-38d0-4766-a7af-d6c9d6302b07
author CarlRabeler
ms.author carlrab

SqlErrorLogEvent Class

[!INCLUDEtsql-appliesto-ss2008-xxxx-xxxx-xxx-md] Provides properties for viewing events in a specified [!INCLUDEssNoVersion] log file.

Syntax

  
class SQLErrorLogEvent   
{  
   stringFileName;  
   stringInstanceName;  
   datetimeLogDate;  
   stringMessage;  
   stringProcessInfo;  
};  

Properties

The SQLErrorLogEvent class defines the following properties.

FileName Data type: string

Access type: Read-only



The name of the error log file.
InstanceName Data type: string

Access type: Read-only

Qualifiers: Key

The name of the instance of [!INCLUDEssNoVersion] where the log file resides.
LogDate Data type: datetime

Access type: Read-only

Qualifiers: Key



The date and time that the event was recorded in the log file.
Message Data type: string

Access type: Read-only



The event message.
ProcessInfo Data type: string

Access type: Read-only



Information about the source server process ID (SPID) for the event.

Remarks

MOF Sqlmgmproviderxpsp2up.mof
DLL Sqlmgmprovider.dll
Namespace \root\Microsoft\SqlServer\ComputerManagement10

Example

The following example shows how to retrieve values for all logged events in a specified log file. To run the example, replace <Instance_Name> with the name of the instance of [!INCLUDEssNoVersion], such as 'Instance1', and replace 'File_Name' with the name of the error log file, such as 'ERRORLOG.1'.

on error resume next  
strComputer = "."  
Set objWMIService = GetObject("winmgmts:" _  
    & "{impersonationLevel=impersonate}!\\" _  
    & strComputer & "\root\MICROSOFT\SqlServer\ComputerManagement10")  
set logEvents = objWmiService.ExecQuery("SELECT * FROM SqlErrorLogEvent WHERE InstanceName = '<Instance_Name>' AND FileName = 'File_Name'")  
  
For Each logEvent in logEvents  
WScript.Echo "Instance Name: " & logEvent.InstanceName & vbNewLine _  
    & "Log Date: " & logEvent.LogDate & vbNewLine _  
    & "Log File Name: " & logEvent.FileName & vbNewLine _  
    & "Process Info: " & logEvent.ProcessInfo & vbNewLine _  
    & "Message: " & logEvent.Message & vbNewLine _  
  
Next  

Comments

When InstanceName or FileName are not provided in the WQL statement, the query will return information for the default instance and the current [!INCLUDEssNoVersion] log file. For example, the following WQL statement will return all log events from the current log file (ERRORLOG) on the default instance (MSSQLSERVER).

"SELECT * FROM SqlErrorLogEvent"  

Security

To connect to a [!INCLUDEssNoVersion] log file through WMI, you must have the following permissions on both the local and remote computers:

  • Read access to the Root\Microsoft\SqlServer\ComputerManagement10 WMI namespace. By default, everyone has read access through the Enable Account permission.

  • Read permission to the folder that contains the error logs. By default the error logs are located in the following path (where <Drive> represents the drive where you installed [!INCLUDEssNoVersion] and <InstanceName> is the name of the instance of [!INCLUDEssNoVersion]):

    <Drive>:\Program Files\Microsoft SQL Server\MSSQL13 .<InstanceName>\MSSQL\Log

If you are connecting through a firewall, ensure that an exception is set in the firewall for WMI on remote target computers. For more information, see Connecting to WMI Remotely Starting with Windows Vista.

See Also

SqlErrorLogFile Class
View Offline Log Files