|
1 | | ---- |
2 | | -description: "SqlErrorLogEvent Class" |
3 | | -title: "SqlErrorLogEvent Class" |
4 | | -ms.custom: "" |
5 | | -ms.date: "03/14/2017" |
6 | | -ms.service: sql |
7 | | -ms.reviewer: "" |
8 | | -ms.subservice: wmi |
9 | | -ms.topic: "reference" |
10 | | -helpviewer_keywords: |
11 | | - - "SqlErrorLogEvent class" |
12 | | - - "SqlErrorLogFile class" |
13 | | -ms.assetid: bde6c467-38d0-4766-a7af-d6c9d6302b07 |
14 | | -author: markingmyname |
15 | | -ms.author: maghan |
16 | | ---- |
17 | | -# SqlErrorLogEvent Class |
18 | | -[!INCLUDE[sqlserver](../../includes/applies-to-version/sqlserver.md)] |
19 | | - Provides properties for viewing events in a specified [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] log file. |
20 | | - |
21 | | -## Syntax |
22 | | - |
23 | | -``` |
24 | | - |
25 | | -class SQLErrorLogEvent |
26 | | -{ |
27 | | - stringFileName; |
28 | | - stringInstanceName; |
29 | | - datetimeLogDate; |
30 | | - stringMessage; |
31 | | - stringProcessInfo; |
32 | | -}; |
33 | | -``` |
34 | | - |
35 | | -## Properties |
36 | | - The SQLErrorLogEvent class defines the following properties. |
37 | | - |
38 | | -| Property | Description | |
39 | | -| -------- | ----------- | |
40 | | -|FileName|Data type: **string**<br /><br /> Access type: Read-only<br /><br /> <br /><br /> The name of the error log file.| |
41 | | -|InstanceName|Data type: **string**<br /><br /> Access type: Read-only<br /><br /> Qualifiers: Key<br /><br /> The name of the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] where the log file resides.| |
42 | | -|LogDate|Data type: **datetime**<br /><br /> Access type: Read-only<br /><br /> Qualifiers: Key<br /><br /> <br /><br /> The date and time that the event was recorded in the log file.| |
43 | | -|Message|Data type: **string**<br /><br /> Access type: Read-only<br /><br /> <br /><br /> The event message.| |
44 | | -|ProcessInfo|Data type: **string**<br /><br /> Access type: Read-only<br /><br /> <br /><br /> Information about the source server process ID (SPID) for the event.| |
45 | | - |
46 | | -## Remarks |
47 | | - |
48 | | -| Type | Name | |
49 | | -| ---- | ---- | |
50 | | -|MOF|Sqlmgmproviderxpsp2up.mof| |
51 | | -|DLL|Sqlmgmprovider.dll| |
52 | | -|Namespace|\root\Microsoft\SqlServer\ComputerManagement10| |
53 | | - |
54 | | -## Example |
55 | | - 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 [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], such as 'Instance1', and replace 'File_Name' with the name of the error log file, such as 'ERRORLOG.1'. |
56 | | - |
57 | | -``` |
58 | | -on error resume next |
59 | | -strComputer = "." |
60 | | -Set objWMIService = GetObject("winmgmts:" _ |
61 | | - & "{impersonationLevel=impersonate}!\\" _ |
62 | | - & strComputer & "\root\MICROSOFT\SqlServer\ComputerManagement10") |
63 | | -set logEvents = objWmiService.ExecQuery("SELECT * FROM SqlErrorLogEvent WHERE InstanceName = '<Instance_Name>' AND FileName = 'File_Name'") |
64 | | - |
65 | | -For Each logEvent in logEvents |
66 | | -WScript.Echo "Instance Name: " & logEvent.InstanceName & vbNewLine _ |
67 | | - & "Log Date: " & logEvent.LogDate & vbNewLine _ |
68 | | - & "Log File Name: " & logEvent.FileName & vbNewLine _ |
69 | | - & "Process Info: " & logEvent.ProcessInfo & vbNewLine _ |
70 | | - & "Message: " & logEvent.Message & vbNewLine _ |
71 | | - |
72 | | -Next |
73 | | -``` |
74 | | - |
75 | | -## Comments |
76 | | - When *InstanceName* or *FileName* are not provided in the WQL statement, the query will return information for the default instance and the current [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] log file. For example, the following WQL statement will return all log events from the current log file (ERRORLOG) on the default instance (MSSQLSERVER). |
77 | | - |
78 | | -``` |
79 | | -"SELECT * FROM SqlErrorLogEvent" |
80 | | -``` |
81 | | - |
82 | | -## Security |
83 | | - To connect to a [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] log file through WMI, you must have the following permissions on both the local and remote computers: |
84 | | - |
85 | | -- Read access to the **Root\Microsoft\SqlServer\ComputerManagement10** WMI namespace. By default, everyone has read access through the Enable Account permission. |
86 | | - |
87 | | -- 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 [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] and \<*InstanceName*> is the name of the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]): |
88 | | - |
89 | | - **\<Drive>:\Program Files\Microsoft SQL Server\MSSQL13** **.\<InstanceName>\MSSQL\Log** |
90 | | - |
91 | | - 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](/windows/win32/wmisdk/connecting-to-wmi-remotely-starting-with-vista). |
92 | | - |
93 | | -## See Also |
94 | | - [SqlErrorLogFile Class](../../relational-databases/wmi-provider-configuration-classes/sqlerrorlogfile-class.md) |
95 | | - [View Offline Log Files](../../relational-databases/logs/view-offline-log-files.md) |
96 | | - |
| 1 | +--- |
| 2 | +title: SqlErrorLogEvent class |
| 3 | +description: Provides properties for viewing events in a specified SQL Server log file. |
| 4 | +author: markingmyname |
| 5 | +ms.author: maghan |
| 6 | +ms.reviewer: randolphwest |
| 7 | +ms.date: 02/23/2023 |
| 8 | +ms.service: sql |
| 9 | +ms.subservice: wmi |
| 10 | +ms.topic: "reference" |
| 11 | +helpviewer_keywords: |
| 12 | + - "SqlErrorLogEvent class" |
| 13 | + - "SqlErrorLogFile class" |
| 14 | +--- |
| 15 | +# SqlErrorLogEvent class |
| 16 | + |
| 17 | +[!INCLUDE[sqlserver](../../includes/applies-to-version/sqlserver.md)] |
| 18 | + |
| 19 | +Provides properties for viewing events in a specified [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] log file. |
| 20 | + |
| 21 | +## Syntax |
| 22 | + |
| 23 | +```csharp |
| 24 | +class SQLErrorLogEvent |
| 25 | +{ |
| 26 | + stringFileName; |
| 27 | + stringInstanceName; |
| 28 | + datetimeLogDate; |
| 29 | + stringMessage; |
| 30 | + stringProcessInfo; |
| 31 | +}; |
| 32 | +``` |
| 33 | + |
| 34 | +## Properties |
| 35 | + |
| 36 | +The SQLErrorLogEvent class defines the following properties. |
| 37 | + |
| 38 | +| Property | Description | |
| 39 | +| --- | --- | |
| 40 | +| FileName | Data type: **string**<br /><br />Access type: Read-only<br /><br />The name of the error log file. | |
| 41 | +| InstanceName | Data type: **string**<br /><br />Access type: Read-only<br /><br />Qualifiers: Key<br /><br />The name of the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] where the log file resides. | |
| 42 | +| LogDate | Data type: **datetime**<br /><br />Access type: Read-only<br /><br />Qualifiers: Key<br /><br />The date and time that the event was recorded in the log file. | |
| 43 | +| Message | Data type: **string**<br /><br />Access type: Read-only<br /><br />The event message. | |
| 44 | +| ProcessInfo | Data type: **string**<br /><br />Access type: Read-only<br /><br />Information about the source server process ID (SPID) for the event. | |
| 45 | + |
| 46 | +## Remarks |
| 47 | + |
| 48 | +| Type | Name | |
| 49 | +| --- | --- | |
| 50 | +| MOF | - `sqlmgmprovider.mof` ([!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions)<br />- `sqlmgmproviderxpsp2up.mof` ([!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and earlier versions) | |
| 51 | +| DLL | `sqlmgmprovider.dll` | |
| 52 | +| Namespace | `\root\Microsoft\SqlServer\ComputerManagement10` | |
| 53 | + |
| 54 | +## Example |
| 55 | + |
| 56 | +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 [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], such as 'Instance1', and replace 'File_Name' with the name of the error log file, such as 'ERRORLOG.1'. |
| 57 | + |
| 58 | +```vbnet |
| 59 | +on error resume next |
| 60 | +strComputer = "." |
| 61 | +Set objWMIService = GetObject("winmgmts:" _ |
| 62 | + & "{impersonationLevel=impersonate}!\\" _ |
| 63 | + & strComputer & "\root\MICROSOFT\SqlServer\ComputerManagement10") |
| 64 | +set logEvents = objWmiService.ExecQuery("SELECT * FROM SqlErrorLogEvent WHERE InstanceName = '<Instance_Name>' AND FileName = 'File_Name'") |
| 65 | + |
| 66 | +For Each logEvent in logEvents |
| 67 | +WScript.Echo "Instance Name: " & logEvent.InstanceName & vbNewLine _ |
| 68 | + & "Log Date: " & logEvent.LogDate & vbNewLine _ |
| 69 | + & "Log File Name: " & logEvent.FileName & vbNewLine _ |
| 70 | + & "Process Info: " & logEvent.ProcessInfo & vbNewLine _ |
| 71 | + & "Message: " & logEvent.Message & vbNewLine _ |
| 72 | + |
| 73 | +Next |
| 74 | +``` |
| 75 | + |
| 76 | +## Comments |
| 77 | + |
| 78 | +When *InstanceName* or *FileName* aren't provided in the WQL statement, the query returns information for the default instance and the current [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] log file. For example, the following WQL statement returns all log events from the current log file (ERRORLOG) on the default instance (MSSQLSERVER). |
| 79 | + |
| 80 | +```wql |
| 81 | +"SELECT * FROM SqlErrorLogEvent" |
| 82 | +``` |
| 83 | + |
| 84 | +## Security |
| 85 | + |
| 86 | +To connect to a [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] log file through WMI, you must have the following permissions on both the local and remote computers: |
| 87 | + |
| 88 | +- Read access to the **Root\Microsoft\SqlServer\ComputerManagement10** WMI namespace. By default, everyone has read access through the Enable Account permission. |
| 89 | + |
| 90 | +- 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 [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] and \<*InstanceName*> is the name of the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]): |
| 91 | + |
| 92 | + **\<Drive>:\Program Files\Microsoft SQL Server\MSSQL13** **.\<InstanceName>\MSSQL\Log** |
| 93 | + |
| 94 | +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](/windows/win32/wmisdk/connecting-to-wmi-remotely-starting-with-vista). |
| 95 | + |
| 96 | +## See also |
| 97 | + |
| 98 | +- [SqlErrorLogFile Class](../../relational-databases/wmi-provider-configuration-classes/sqlerrorlogfile-class.md) |
| 99 | +- [View Offline Log Files](../../relational-databases/logs/view-offline-log-files.md) |
0 commit comments