Audit.Enabled プロパティ

SQL Server のインスタンスで参照されている監査が有効かどうかを示す Boolean 値を取得します。 

名前空間:  Microsoft.SqlServer.Management.Smo
アセンブリ:  Microsoft.SqlServer.Smo (Microsoft.SqlServer.Smo.dll)

構文

'宣言
<SfcPropertyAttribute(SfcPropertyFlags.Standalone)> _
Public ReadOnly Property Enabled As Boolean 
    Get
'使用
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

プロパティ値

型: System.Boolean
テーブルがシステム テーブルを参照するかどうかを示す Boolean 値。参照されている監査が SQL Server のインスタンスで有効な場合は True、それ以外の場合は False (既定値) です。

使用例

次のコード例では、監査が現在有効かどうかを確認し、有効な場合はコンソールに通知を表示する方法を示します。

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

関連項目

参照

Audit クラス

Microsoft.SqlServer.Management.Smo 名前空間