Skip to content

Latest commit

 

History

History
98 lines (71 loc) · 4.48 KB

File metadata and controls

98 lines (71 loc) · 4.48 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic
SqlErrorLogFile class
Provides properties for viewing information about a SQL Server log file.
markingmyname
maghan
randolphwest
02/23/2023
sql
wmi
reference

SqlErrorLogFile class

[!INCLUDEsqlserver]

Provides properties for viewing information about a [!INCLUDEssNoVersion] log file.

Syntax

class SQLErrorLogFile
{
    uint32ArchiveNumber;
    stringInstanceName;
    datetimeLastModified;
    uint32LogFileSize;
    stringName;
};

Properties

The SQLErrorLogFile class defines the following properties.

Property Description
ArchiveNumber Data type: uint32

Access type: Read-only

The archive number for the log file.
InstanceName Data type: string

Access type: Read-only

Qualifiers: Key

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

Access type: Read-only

The date that the log file was last modified.
LogFileSize Data type: uint32

Access type: Read-only

The log file size, in bytes.
Name Data type: string

Access type: Read-only

Qualifiers: Key

The name of the log file.

Remarks

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

Example

The following example retrieves information about all [!INCLUDEssNoVersion] log files on a specified instance of [!INCLUDEssNoVersion]. To run the example, replace <Instance_Name> with the name of the instance, for example, 'Instance1'.

on error resume next
set strComputer = "."
set objWMIService = GetObject("winmgmts:\\.\root\Microsoft\SqlServer\ComputerManagement10")
set LogFiles = objWmiService.ExecQuery("SELECT * FROM SqlErrorLogFile WHERE InstanceName = '<Instance_Name>'")
  
For Each logFile in LogFiles
  
WScript.Echo "Instance Name:  " & logFile.InstanceName & vbNewLine _
    & "Log File Name:  " & logFile.Name & vbNewLine _
    & "Archive Number: " & logFile.ArchiveNumber & vbNewLine _
    & "Log File Size:  " & logFile.LogFileSize & " bytes" & vbNewLine _
    & "Last Modified:  " & logFile.LastModified & vbNewLine _
  
Next

Comments

When InstanceName isn't provided in the WQL statement, the query returns information for the default instance. For example, the following WQL statement returns information about all log files from the default instance (MSSQLSERVER).

"SELECT * FROM SqlErrorLogFile"

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.

    [!NOTE]
    For information about how to verify WMI permissions, see the Security section of the topic View Offline Log Files.

  • 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\MSSQL11 .<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.

See also