Export (0) Print
Expand All

SqlErrorLogFile Class

Provides properties for viewing information about a SQL Server log file.

class SQLErrorLogFile


The SQLErrorLogFile class defines the following properties.


Data type: uint32

Access type: Read-only


The archive number for the log file.


Data type: string

Access type: Read-only

Qualifiers: Key


The name of the instance of SQL Server where the log file resides.


Data type: datetime

Access type: Read-only


The date that the log file was last modified.


Data type: uint32

Access type: Read-only


The log file size, in bytes.


Data type: string

Access type: Read-only

Qualifiers: Key


The name of the log file.


Sqlmgmprovider xpsp2up.mof





The following example retrieves information about all SQL Server log files on a specified instance of SQL Server. 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 _


When InstanceName is not provided in the WQL statement, the query will return information for the default instance. For example, the following WQL statement will return information about all log files from the default instance (MSSQLSERVER).

"SELECT * FROM SqlErrorLogFile"

To connect to a SQL Server 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 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 SQL Server and <InstanceName> is the name of the instance of SQL Server):

    <Drive>:\Program Files\Microsoft SQL Server\MSSQL11 .<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.

Community Additions

© 2015 Microsoft