Audit.Enabled Audit.Enabled Audit.Enabled Property

Definition

Gets the Boolean value that specifies whether the referenced audit is enabled on the instance of SQL Server.

public:
 property bool Enabled { bool get(); };
[Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcProperty(Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcPropertyFlags.Standalone)]
public bool Enabled { get; }
Public ReadOnly Property Enabled As Boolean
Property Value

A Boolean value that specifies whether the table references a system table.

If True, the referenced audit is enabled on the instance of SQL Server; otherwise, False (default).

Examples

The following code example shows how to check whether the audit is currently enabled and display a notice on the console if it is.

C#

using System;  
using Microsoft.SqlServer.Management.Smo;  

namespace samples  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            //Create the audit  
            Server dbServer = new Server("(local)");  
            Audit dbAudit = new Audit(dbServer, "Test Audit");  
            dbAudit.DestinationType = AuditDestinationType.File;  
            dbAudit.FilePath = "C:\\AuditDirectory";  
            dbAudit.Create();  

            //Enable the audit  
            dbAudit.Enable();  

            //Check to see if the audit is enabled  
            if (dbAudit.Enabled)  
            {  
               Console.WriteLine("The audit is enabled.");  
            }  
            Else  
            {  
               Console.WriteLine("The audit is disabled.");  
            }  
        }  
    }  
}  

Powershell

#Create the audit  
$dbServer = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$dbAudit = New-Object Microsoft.SqlServer.Management.Smo.Audit($dbServer, "Test Audit")  
$dbAudit.DestinationType = [Microsoft.SqlServer.Management.Smo.AuditDestinationType]'File'  
$dbAudit.FilePath = "C:\AuditDirectory"  
$dbAudit.Create()  

#Enable the audit  
$dbAudit.Enable()  

#check to see if the audit is enabled  
If ($dbAudit.Enabled -eq $TRUE)  
{  
   Write-Host "The audit is enabled"  
{  
Else  
{  
   Write-Host "The audit is disabled"  
}  

Applies to