Udostępnij za pośrednictwem


Właściwość Audit.Enabled

Pobiera Boolean wartość określająca, czy odwołanie inspekcji jest włączone na wystąpienie SQL Server.

Przestrzeń nazw:  Microsoft.SqlServer.Management.Smo
Zestaw:  Microsoft.SqlServer.Smo (w Microsoft.SqlServer.Smo.dll)

Składnia

'Deklaracja
<SfcPropertyAttribute(SfcPropertyFlags.Standalone)> _
Public ReadOnly Property Enabled As Boolean
    Get
'Użycie
Dim instance As Audit
Dim value As Boolean

value = instance.Enabled
[SfcPropertyAttribute(SfcPropertyFlags.Standalone)]
public bool Enabled { get; }
[SfcPropertyAttribute(SfcPropertyFlags::Standalone)]
public:
property bool Enabled {
    bool get ();
}
[<SfcPropertyAttribute(SfcPropertyFlags.Standalone)>]
member Enabled : bool
function get Enabled () : boolean

Wartość właściwości

Typ: System.Boolean
A Boolean wartość określająca, czy tabela odwołuje się do tabela systemowa.
Jeśli True, odwołanie inspekcji jest włączone na wystąpienie SQL Server; w przeciwnym razie False (domyślnie).

Przykłady

Poniższy przykład kodu pokazuje, jak sprawdzić, czy jest włączona inspekcja i wyświetlić ogłoszenie na konsoli, jeśli jest.

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"
}