Skip to content

Latest commit

 

History

History
97 lines (73 loc) · 4.57 KB

File metadata and controls

97 lines (73 loc) · 4.57 KB
title SqlErrorLogFile Class
ms.custom
ms.date 03/14/2017
ms.prod sql
ms.prod_service database-engine
ms.reviewer
ms.technology wmi
ms.topic reference
ms.assetid 2b83ae4a-c0d4-414c-b6e5-a41ec7c13159
author CarlRabeler
ms.author carlrab

SqlErrorLogFile Class

[!INCLUDEtsql-appliesto-ss2008-xxxx-xxxx-xxx-md] 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.

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

MOF Sqlmgmprovider xpsp2up.mof
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 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"  

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

See Also

SqlErrorLogEvent Class
View Offline Log Files