共用方式為


Audit.Disable 方法

Disables the audit.

命名空間:  Microsoft.SqlServer.Management.Smo
組件:  Microsoft.SqlServer.Smo (在 Microsoft.SqlServer.Smo.dll 中)

語法

'宣告
Public Sub Disable
'用途
Dim instance As Audit

instance.Disable()
public void Disable()
public:
void Disable()
member Disable : unit -> unit
public function Disable()

備註

The Disable method disables the audit, if it has already been enabled. If the audit has not been previously enabled using the Enable method, nothing will happen when Disable is called.

範例

The following code example demonstrates how to disable an audit.

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();
            Console.WriteLine("The audit is enabled")

            //Disable the audit
            dbAudit.Disable();
            if (dbAudit.Enabled == false)
            { 
            Console.WriteLine("The audit has been 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()
Write-Host "The audit is enabled"

#Disable the audit
$dbAudit.Disable()
If ($dbAudit.Enabled -eq $FALSE)
{
   Write-Host "The audit has been disabled"
}

請參閱

參考

Audit 類別

Microsoft.SqlServer.Management.Smo 命名空間