Rename Method

Audit.Rename Method (String)


Changes the name of the audit to the specified string.

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

public void Rename(
	string newname


Type: System.String

A string object specifying the new name of the audit.

The new audit name must be unique. Attempting to set the audit name to the same name as an existing audit will result in a FailedOperationException.

The following code example demonstrates how to rename 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";

            //Rename the audit and display the new name on the console
            dbAudit.Rename("New Test Audit Name");


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

#Rename the audit and display the new name
$dbAudit.Rename("New Test Audit name")
Write-Host $dbAudit.Name
Return to top
© 2015 Microsoft