Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Disable Method

Audit.Disable Method

Disables the audit.

Namespace:  Microsoft.SqlServer.Management.Smo
Assembly:  Microsoft.SqlServer.Smo (in Microsoft.SqlServer.Smo.dll)

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


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

           //Enable the audit
            Console.WriteLine("The audit is enabled")

            //Disable the audit
            if (dbAudit.Enabled == false)
            Console.WriteLine("The audit has been disabled");


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

#Enable the audit
Write-Host "The audit is enabled"

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

Community Additions

© 2015 Microsoft