Méthode Rename
Changes the name of the audit to the specified string.
Espace de noms : Microsoft.SqlServer.Management.Smo
Assembly : Microsoft.SqlServer.Smo (en Microsoft.SqlServer.Smo.dll)
Syntaxe
'Déclaration
Public Sub Rename ( _
newname As String _
)
'Utilisation
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
)
Paramètres
- newname
Type : System. . :: . .String
A string object specifying the new name of the audit.
Implémente
Notes
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.
Exemples
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