Поделиться через


Метод Script

Generates a Transact-SQL script that can be used to re-create the instance of SQL Server affinity settings as specified in the AffinityInfo object.

Пространство имен:  Microsoft.SqlServer.Management.Smo
Сборка:  Microsoft.SqlServer.Smo (в Microsoft.SqlServer.Smo.dll)

Синтаксис

'Декларация
Public Function Script As StringCollection
'Применение
Dim instance As AffinityInfo
Dim returnValue As StringCollection

returnValue = instance.Script()
public StringCollection Script()
public:
virtual StringCollection^ Script() sealed
abstract Script : unit -> StringCollection 
override Script : unit -> StringCollection 
public final function Script() : StringCollection

Возвращаемое значение

Тип: System.Collections.Specialized. . :: . .StringCollection
A StringCollection system object value that contains a list of Transact-SQL command batch statements that defines the AffinityInfo object.

Реализует

IScriptable. . :: . .Script() () () ()

Примеры

This example shows you how to display the Transact-SQL statements needed to set an Instance of SQL Server to the current values stored in a AffinityInfo object.

using System;
using System.Collections.Specialized;
using Microsoft.SqlServer.Management.Smo;

namespace samples
{
    class Program
    {
        static void Main(string[] args)
        {
            Server dbServer = new Server("(local)");

            dbServer.Refresh();
            StringCollection s = dbServer.AffinityInfo.Script();
            foreach (string sv in s)
                Console.WriteLine(sv);
        }
    }
}

Powershell

#Create the server. 
$dbServer = new-Object Microsoft.SqlServer.Smo.Server("(local)")
$dbServer.Refresh()

$s = New-Object System.Collections.Specialized.StringCollection()
$s = $dbServer.AffinityInfo.Script()

Foreach ($sv in $s)
{
   Write-Host $sv
}