Επεξεργασία

Κοινή χρήση μέσω


SqlErrorLogFile class

Applies to: SQL Server

Provides properties for viewing information about a SQL Server 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 SQL Server 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 (SQL Server 2022 (16.x) and later versions)
- sqlmgmproviderxpsp2up.mof (SQL Server 2019 (15.x) and earlier versions)
DLL sqlmgmprovider.dll
Namespace \root\Microsoft\SqlServer\ComputerManagement10

Example

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 _
  
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 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

    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'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