AffinityInfo 类

The AffinityInfo object represents the Affinity settings for all CPUs and NUMA nodes on an Instance of SQL Server. Access to the AffinityInfo object is provided though the Server object.

继承层次结构

System. . :: . .Object
  Microsoft.SqlServer.Management.Smo..::..AffinityInfo

命名空间:  Microsoft.SqlServer.Management.Smo
程序集:  Microsoft.SqlServer.Smo(在 Microsoft.SqlServer.Smo.dll 中)

语法

声明
Public NotInheritable Class AffinityInfo _
    Implements IAlterable, IScriptable
用法
Dim instance As AffinityInfo
public sealed class AffinityInfo : IAlterable, 
    IScriptable
public ref class AffinityInfo sealed : IAlterable, 
    IScriptable
[<SealedAttribute>]
type AffinityInfo =  
    class
        interface IAlterable
        interface IScriptable
    end
public final class AffinityInfo implements IAlterable, IScriptable

AffinityInfo 类型公开以下成员。

属性

  名称 说明
公共属性 AffinityType Gets or Sets the AffinityType()()()() member of the AffinityInfo class. Valid values are Auto or Manual.
公共属性 Cpus The Cpus()()()() member is a collection that represents the CPU settings for all CPUs on an Instance of SQL Server.
公共属性 NumaNodes The NumaNode()()()() member is a collection that contains the NUMA node settings for an Instance of SQL Server.
公共属性 Parent This gets the parent object of the AffinityInfo object. This value is the same as the Server object that contains the AffinityInfo()()()() member.

页首

方法

  名称 说明
公共方法 Alter This method updates the server with the current values in the AffinityInfo class.
公共方法 Equals (从 Object 继承。)
受保护方法 Finalize (从 Object 继承。)
公共方法 GetHashCode (从 Object 继承。)
公共方法 GetType (从 Object 继承。)
受保护方法 MemberwiseClone (从 Object 继承。)
公共方法 Refresh This method fills in the Cpus()()()() and NumaNode()()()() with the local server settings.
公共方法 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.
公共方法 Script(ScriptingOptions) 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.
公共方法 ToString (从 Object 继承。)

页首

注释

To get AffinityInfo object properties, users can be a member of the public fixed server role.

To set any AffinityInfo object properties and run the Alter method, users must have ALTER permission on the database.

To create a AffinityInfo object, users must have ALTER ANY APPLICATION role permission on the parent database.

To drop an AffinityInfo object, users must be the owner of the application role or have ALTER ANY APPLICATION role permission on the parent database.

To grant, deny, and revoke permission on the AffinityInfo object, users must have CONTROL permission on the application role.

示例

This example shows you how to set all of the CPU’s on an instance of SQL Server to hard affinity.

C#

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

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

            foreach (Cpu cpu in dbServer.AffinityInfo.Cpus)
                cpu.AffinityMask = true;

            dbServer.AffinityInfo.Alter();
        }
    }
}

Powershell

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

//Set the Affinity Type
$dbServer.AffinityInfo.AffinityType = [Microsoft.SqlServer.Management.Smo.AffinityType]'Manual'

//Set each CPU to Hard affinity and update
foreach ($cpu In $dbServer.AffinityInfo.Cpus)
{
   $cpu.AffinityMask = $True
   $dbServer.AffinityInfo.Alter() 
}

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。不保证所有实例成员都是线程安全的。