Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

AffinityInfo Class


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.

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


public sealed class AffinityInfo : AffinityInfoBase


Gets or sets the affinity type of the AffinityInfoBase.(Inherited from AffinityInfoBase.)


The M:Microsoft.SqlServer.Management.Smo.AffinityInfo.Cpus member is a collection that represents the CPU settings for all CPUs on an Instance of SQL Server.


Gets a collection that contains the NUMA node settings.(Inherited from AffinityInfoBase.)


This gets the parent object of the AffinityInfo object. This value is the same as the Server object that contains the M:Microsoft.SqlServer.Management.Smo.AffinityInfo member.


Updates the AffinityInfo object property changes on the instance of SQL Server.(Inherited from AffinityInfoBase.)


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)


This method fills in the M:Microsoft.SqlServer.Management.Smo.Cpus and M:Microsoft.SqlServer.Management.Smo.NumaNode with the local server settings.(Overrides AffinityInfoBase.Refresh().)


Generates a Transact-SQL script.(Inherited from AffinityInfoBase.)


Generates a Transact-SQL script.(Inherited from AffinityInfoBase.)


(Inherited from 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 M:Microsoft.SqlServer.Management.Smo.AffinityInfo.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.


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;



//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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft