title | description | author | ms.author | ms.reviewer | ms.date | ms.service | ms.subservice | ms.topic | helpviewer_keywords | ||
---|---|---|---|---|---|---|---|---|---|---|---|
SqlErrorLogEvent class |
Provides properties for viewing events in a specified SQL Server log file. |
markingmyname |
maghan |
randolphwest |
02/23/2023 |
sql |
wmi |
reference |
|
[!INCLUDEsqlserver]
Provides properties for viewing events in a specified [!INCLUDEssNoVersion] log file.
class SQLErrorLogEvent
{
stringFileName;
stringInstanceName;
datetimeLogDate;
stringMessage;
stringProcessInfo;
};
The SQLErrorLogEvent class defines the following properties.
Property | Description |
---|---|
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 session ID (SPID) for the event. |
Type | Name |
---|---|
MOF | - sqlmgmprovider.mof ([!INCLUDE sssql22-md] and later versions)- sqlmgmproviderxpsp2up.mof ([!INCLUDE sssql19-md] and earlier versions) |
DLL | sqlmgmprovider.dll |
Namespace | \root\Microsoft\SqlServer\ComputerManagement10 |
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
When InstanceName or FileName aren't provided in the WQL statement, the query returns information for the default instance and the current [!INCLUDEssNoVersion] log file. For example, the following WQL statement returns all log events from the current log file (ERRORLOG) on the default instance (MSSQLSERVER).
"SELECT * FROM SqlErrorLogEvent"
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're 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.