共用方式為


Audit.Rename 方法

Changes the name of the audit to the specified string.

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

語法

'宣告
Public Sub Rename ( _
    newname As String _
)
'用途
Dim instance As Audit 
Dim newname As String

instance.Rename(newname)
public void Rename(
    string newname
)
public:
virtual void Rename(
    String^ newname
) sealed
abstract Rename : 
        newname:string -> unit  
override Rename : 
        newname:string -> unit
public final function Rename(
    newname : String
)

參數

  • newname
    型別:System.String
    A string object specifying the new name of the audit.

實作

IRenamable.Rename(String)

備註

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.

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();

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

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()

#Rename the audit and display the new name
$dbAudit.Rename("New Test Audit name")
Write-Host $dbAudit.Name

請參閱

參考

Audit 類別

Microsoft.SqlServer.Management.Smo 命名空間