Cpu.AffinityMask Property


Gets or sets the T:Microsoft.SqlServer.Management.Smo.AffinityMask member of the Cpu class.

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

public bool AffinityMask { get; set; }

Property Value

Type: System.Boolean

Returns a Boolean that shows the current affinity mask setting for the CPU that is represented by this Cpu instance.

Access to the Cpu class is though the T:Microsoft.SqlServer.Management.Smo.Server.AffinityInfo.Cpus collection.

To change the CPU settings on an instance of SQL Server, users must have ALTER permission on the database.

The following code example shows how to display the affinity setting for each CPU in the local instance of SQL Server.


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

namespace samples
    class Program
        static void Main(string[] args)
            Server dbServer = new Server("(local)");
            foreach(Cpu cpu in dbServer.AffinityInfo.Cpus)
                Console.WriteLine("Affinity is {0} for CPU ID {1}.",
                    (cpu.AffinityMask) ? "set" : "not set",


$dbServer = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
Foreach ($cpu in $dbServer.AffinityInfo.Cpus)
   If ($cpu.AffinityMask = $TRUE)
      Write-Host "Affinity is set for" $cpu.ID
      Write-Host "Affinity is not set for" $cpu.ID

Return to top