共用方式為


AvailabilityGroup Class

Definition

An Availability Group (AG) is the unit of high availability. It represents a collection of related databases that form the business critical application that needs high availability and disaster recovery capability.

[Microsoft.SqlServer.Management.Facets.EvaluationMode(Microsoft.SqlServer.Management.Dmf.AutomatedPolicyEvaluationMode.CheckOnSchedule)]
[Microsoft.SqlServer.Management.Sdk.Sfc.PhysicalFacet]
public sealed class AvailabilityGroup : Microsoft.SqlServer.Management.Smo.NamedSmoObject, Microsoft.SqlServer.Management.Common.IAlterable, Microsoft.SqlServer.Management.Common.ICreatable, Microsoft.SqlServer.Management.Common.IDropIfExists, Microsoft.SqlServer.Management.Common.IDroppable, Microsoft.SqlServer.Management.Smo.IObjectPermission, Microsoft.SqlServer.Management.Smo.IScriptable
[<Microsoft.SqlServer.Management.Facets.EvaluationMode(Microsoft.SqlServer.Management.Dmf.AutomatedPolicyEvaluationMode.CheckOnSchedule)>]
[<Microsoft.SqlServer.Management.Sdk.Sfc.PhysicalFacet>]
type AvailabilityGroup = class
    inherit NamedSmoObject
    interface IObjectPermission
    interface ICreatable
    interface IAlterable
    interface IDroppable
    interface IDropIfExists
    interface IScriptable
[<Microsoft.SqlServer.Management.Facets.EvaluationMode(Microsoft.SqlServer.Management.Dmf.AutomatedPolicyEvaluationMode.CheckOnSchedule)>]
[<Microsoft.SqlServer.Management.Sdk.Sfc.PhysicalFacet>]
type AvailabilityGroup = class
    inherit NamedSmoObject
    interface ICreatable
    interface IAlterable
    interface IDroppable
    interface IDropIfExists
    interface IScriptable
    interface IObjectPermission
Public NotInheritable Class AvailabilityGroup
Inherits NamedSmoObject
Implements IAlterable, ICreatable, IDropIfExists, IDroppable, IObjectPermission, IScriptable
Inheritance
Attributes
Implements

Constructors

AvailabilityGroup()
AvailabilityGroup(Server, String)

Fields

m_ExtendedProperties (Inherited from SqlSmoObject)
singletonParent

Regular SMO objects access the parent class reference through parentColl (corresponding collection in parent class). Singleton class has no collection in parent.

(Inherited from SqlSmoObject)

Properties

AutomatedBackupPreference
AvailabilityDatabases

The collection of availability databases contained in the availability group.

AvailabilityGroupListeners

The collection of replicas participating in the availability group.

AvailabilityReplicas

The collection of replicas participating in the availability group.

BasicAvailabilityGroup
ClusterType
ClusterTypeWithDefault

Gets the cluster type of the availability group, if the primary server is 130 or lower, return Wsfc instead

DatabaseEngineEdition

Returns the DatabaseEngineEdition of the SMO object

(Inherited from SqlSmoObject)
DatabaseEngineType

Returns the DatabaseEngineType of the SMO object

(Inherited from SqlSmoObject)
DatabaseHealthTrigger
DatabaseReplicaStates

A collection of objects represeting the states of physical database replicas participating in the availability groups. On an Availability Replica in a primary role, the collection returns information on all Database Replicas on all Availability Replicas. On an Availability Replica in a secondary role, the collection returns information on just the local Database Replicas.

The collection is keyed on the "AvailabilityReplicaServerName" and "AvailabilityDatabaseName" properties of the DatabaseReplciaState object.

DtcSupportEnabled
ExecuteForScalar (Inherited from SqlSmoObject)
ExecutionManager (Inherited from SqlSmoObject)
FailureConditionLevel
HealthCheckTimeout
ID
IsDistributedAvailabilityGroup
IsTouched

Whether the object has been touched for unconditional scripting of Alter

(Inherited from SqlSmoObject)
LocalReplicaRole
Name (Inherited from NamedSmoObject)
ObjectInSpace (Inherited from SqlSmoObject)
Parent
ParentCollection

Returns the collection that contains the object. May be null.

(Inherited from SqlSmoObject)
PrimaryReplicaServerName
Properties (Inherited from SqlSmoObject)
RequiredSynchronizedSecondariesToCommit
ScalarResult (Inherited from SqlSmoObject)
ServerVersion

Returns the ServerVersion of the Server that contains the object. If the object is not associated with a connected Server, the highest known server version is returned.

(Inherited from SqlSmoObject)
State

Returns the state of the object

(Inherited from SmoObjectBase)
UniqueId
Urn

Returns the Urn of the object, computed on the fly

(Inherited from SqlSmoObject)
UrnSuffix

returns the name of the type in the urn expression

UserData (Inherited from SmoObjectBase)

Methods

AddDatabaseContext(StringCollection)

method get called from the create script related method (from derived classes like Table, Index etc..)

(Inherited from SqlSmoObject)
Alter()

Alter an availability group.

This is called when the alterable AG properties are changed.

AlterImpl() (Inherited from SqlSmoObject)
AlterImplWorker() (Inherited from SqlSmoObject)
BindDefaultImpl(String, String, Boolean) (Inherited from SqlSmoObject)
BindRuleImpl(String, String, Boolean) (Inherited from SqlSmoObject)
CheckObjectState() (Inherited from SqlSmoObject)
CheckObjectState(Boolean)

This is a virtual function, so that derived classes can override it if they want to do additional checks on the state of the object

(Inherited from SqlSmoObject)
CheckObjectStateImpl(Boolean)

Checks object state Because it is not recusrive, this function can be called directly and which means derived classes can't supply their own validation

(Inherited from SqlSmoObject)
CleanObject() (Inherited from SqlSmoObject)
Create()

Create an availability group that has been specified on the client on the back end.

The availability group creation will include any availability replicas or availability databases added to the object before creation.

CreateImpl() (Inherited from SqlSmoObject)
CreateOrAlterImpl() (Inherited from SqlSmoObject)
DemoteAsSecondary()

Demote the current replica as secondary

Deny(ObjectPermissionSet, String, Boolean)
Deny(ObjectPermissionSet, String)
Deny(ObjectPermissionSet, String[], Boolean)
Deny(ObjectPermissionSet, String[])
Discover()

Best Effort Discovery mechanism : This method reflects upon metadata and gets all available objects

(Inherited from SqlSmoObject)
Drop()

Drop an availability group.

DropIfExists()

Drops the object with IF EXISTS option. If object is invalid for drop function will return without exception.

DropImpl(Boolean, Boolean)

For drop calls on the user database in Azure, the connection will be closed as the database is dropped The ExecutionManager will normally attempt to retry such calls by reopening the connection We want to avoid this retry when handleSevereError is true.

(Inherited from SqlSmoObject)
DropImpl(Boolean)

drops the object

(Inherited from SqlSmoObject)
DropImplWorker(Urn, Boolean)

drops the object

(Inherited from SqlSmoObject)
EnumObjectPermissions()
EnumObjectPermissions(ObjectPermissionSet)
EnumObjectPermissions(String, ObjectPermissionSet)
EnumObjectPermissions(String)
EnumReplicaClusterNodes()

Returns a DataTable with information about the cluster configuration of the availability group. For each replica, a row is present for each node that hosts the replica. A replica can be hosted by multiple nodes if the replica is hosted on an FCI. The schema of this table is: ReplicaName (sysname) | NodeName (sysname) | MemberType (tinyint) | MemberState (tinyint) | NumberOfQuorumVotes (int)

ExecuteNonQuery(StringCollection, Boolean, Boolean)

Executes sql statements

(Inherited from SqlSmoObject)
ExecuteRenameQuery(String)

Creates the Rename query for a SqlSmoObject and Executes it on the Server.

(Inherited from NamedSmoObject)
ExecuteWithModes(SqlExecutionModes, Action)

Executes the given action under the given execution modes.

Resets the original modes after the action completes or fails.

(Inherited from SqlSmoObject)
Failover()

Perform a manual failover of this availability group to the server specified by the Parent property. This server should be participating in the availability group as a secondary replica. The result of the action will be to designate this server as the primary of this availability group. This action has no possibility of data loss.

FailoverWithPotentialDataLoss()

Perform a force failover of this availability group to the server specified by the Parent property. This server should be participating in the availability group as a secondary replica. The result of the action will be to designate this server as the primary of this availability group. This action has the possibility of data loss if the databases on the replica are not synchronized with the primary.

FormatSqlVariant(Object) (Inherited from SqlSmoObject)
GenerateAlterEvent() (Inherited from SqlSmoObject)
GenerateAlterEvent(Urn, Object) (Inherited from SqlSmoObject)
GetContextDB() (Inherited from SqlSmoObject)
GetDBName() (Inherited from SqlSmoObject)
GetDisabledProperties(ScriptingPreferences)

Provides an enumerable of properties that are explicitly disabled for specific server types or editions. This is not a list of all properties that don't work for the specified target.

(Inherited from SqlSmoObject)
GetFragOptionString(FragmentationOption) (Inherited from SqlSmoObject)
GetPropValue(String)

Retrieve the property value from : - The property bag directly if property is available (dirty or retrieved) - A call to our OnPropertyMissing method otherwise

Will throw an exception if the property value is NULL in either case.

(Inherited from SqlSmoObject)
GetPropValueOptional(String)

Retrieve the property value from : - The property bag if the state is creating or we're in Design Mode (possible NULL value) - A call to our OnPropertyMissing method otherwise (will throw exception if value is NULL)

(Inherited from SqlSmoObject)
GetPropValueOptional<T>(String, T)

Returns the value of the named property. If the object is in the Creating state and the property has not yet been set the defaultValue is returned. If the object exists the defaultValue is ignored and the actual value is returned.

(Inherited from SqlSmoObject)
GetPropValueOptionalAllowNull(String)

Retrieve the property value from : - The property bag if the state is creating or we're in Design Mode (possible NULL) - A call to our OnPropertyMissing method otherwise (possible NULL)

(Inherited from SqlSmoObject)
GetRealValue(Property, Object)

Returns the real value for the property.

(Inherited from SqlSmoObject)
GetServerName() (Inherited from SqlSmoObject)
GetServerObject() (Inherited from SqlSmoObject)
GetSqlServerVersionName()

Gets the sqlserver public name for the current connection, e.g: will transfer "SQLTOOLS2008-2" to "SQL Server 2008".

(Inherited from SqlSmoObject)
GetStringComparer()

Returns the comparer used by all child object collections to perform comparison of object names. The comparer of a Server is based on the collation of master The comparer of a Database and its children is based on the database collation

(Inherited from SqlSmoObject)
GetUrnRecursive(StringBuilder, UrnIdOption)

Computes the Urn for the object, potentially including other fields in the definition besides the key fields.

(Inherited from SqlSmoObject)
GetUrnRecursive(StringBuilder)

Computes the Urn for the object.

(Inherited from SqlSmoObject)
Grant(ObjectPermissionSet, String, Boolean, String)
Grant(ObjectPermissionSet, String, Boolean)
Grant(ObjectPermissionSet, String)
Grant(ObjectPermissionSet, String[], Boolean, String)
Grant(ObjectPermissionSet, String[], Boolean)
Grant(ObjectPermissionSet, String[])
ImplInitialize(String[], OrderBy[]) (Inherited from SqlSmoObject)
InitChildCollection(Urn, Boolean)

Initializes the child object collection associated with the given type. For example, the name Column would initialize the Columns collection.

(Inherited from SqlSmoObject)
Initialize() (Inherited from SqlSmoObject)
Initialize(Boolean)

Initializes the object, by reading its properties from the enumerator

(Inherited from SqlSmoObject)
IsExpressSku()

Returns whether the server containing this object is an Express SKU

(Inherited from SqlSmoObject)
IsObjectDirty() (Inherited from SqlSmoObject)
IsObjectInitialized() (Inherited from SqlSmoObject)
IsObjectInSpace() (Inherited from SqlSmoObject)
IsSupportedProperty(String)

Validate whether the specified property is supported in current server environment

(Inherited from SqlSmoObject)
IsVersion80SP3() (Inherited from SqlSmoObject)
IsVersion90AndAbove() (Inherited from SqlSmoObject)
MarkDropped() (Inherited from SqlSmoObject)
MarkForDropImpl(Boolean) (Inherited from SqlSmoObject)
PostAlter()

this function is meant to be overriden by derived classes, if they have to do supplimentary actions after altering the object

(Inherited from SqlSmoObject)
PostCreate()

this function is meant to be overriden by derived classes, if they have to do supplimentary actions after object creation

(Inherited from SqlSmoObject)
PostDrop()

this function is meant to be overriden by derived classes, if they have to do supplimentary actions after dropping the object

(Inherited from SqlSmoObject)
Refresh()

refreshes the object's properties by reading them from the server

(Inherited from SqlSmoObject)
RenameImpl(String)

change object name

(Inherited from NamedSmoObject)
RenameImplWorker(String) (Inherited from NamedSmoObject)
Revoke(ObjectPermissionSet, String, Boolean, Boolean, String)
Revoke(ObjectPermissionSet, String, Boolean, Boolean)
Revoke(ObjectPermissionSet, String)
Revoke(ObjectPermissionSet, String[], Boolean, Boolean, String)
Revoke(ObjectPermissionSet, String[], Boolean, Boolean)
Revoke(ObjectPermissionSet, String[])
Script()

Generate the script for creating this availability group.

Script(ScriptingOptions)

Generate a script for this availability group using the specified scripting options.

ScriptImpl() (Inherited from SqlSmoObject)
ScriptImpl(ScriptingOptions)

Returns a StringCollection object with the script for the object. This method throws an error if ScriptData is true

(Inherited from SqlSmoObject)
SetAccessToken(IRenewableToken)

Set the accessToken for connection.

(Inherited from SqlSmoObject)
SetParentImpl(SqlSmoObject) (Inherited from SqlSmoObject)
SetSchemaOwned() (Inherited from NamedSmoObject)
SetState(SqlSmoState)

Sets the object state (Existing, Dropped etc.) Applications should avoid using this method.

(Inherited from SmoObjectBase)
ThrowIfAboveVersion100(String)

Throws an exception if the ServerVersion major version for this object is above 10.0 (SQL 2008)

(Inherited from SqlSmoObject)
ThrowIfAboveVersion80(String)

Throws an exception if the ServerVersion major version for this object is above 8.0 (SQL 2000)

(Inherited from SqlSmoObject)
ThrowIfBelowVersion100(String)

Throws an exception if the ServerVersion major version for this object is below 10.0 (SQL 2008)

(Inherited from SqlSmoObject)
ThrowIfBelowVersion110(String)

Throws an UnsupportedVersionException if either the source or destination server is below 11.0 (SQL 2012)

(Inherited from SqlSmoObject)
ThrowIfBelowVersion110Prop(String)

Throws an exception with text saying the specified property is not supported if the ServerVersion major version for this object is below 11.0 (SQL 2012)

(Inherited from SqlSmoObject)
ThrowIfBelowVersion120(String)

Throws an exception if the ServerVersion major version for this object is below 12.0 (SQL 2014)

(Inherited from SqlSmoObject)
ThrowIfBelowVersion120Prop(String)

Throws an exception with text saying the specified property is not supported if the ServerVersion major version for this object is below 12.0 (SQL 2014)

(Inherited from SqlSmoObject)
ThrowIfBelowVersion130(String)

Throws an exception if the ServerVersion major version for this object is below 13.0 (SQL 2016)

(Inherited from SqlSmoObject)
ThrowIfBelowVersion130Prop(String)

Throws an exception with text saying the specified property is not supported if the ServerVersion major version for this object is below 13.0 (SQL 2016)

(Inherited from SqlSmoObject)
ThrowIfBelowVersion140(String)

Throws an exception if the ServerVersion major version for this object is below 14.0 (SQL 2017)

(Inherited from SqlSmoObject)
ThrowIfBelowVersion140Prop(String)

Throws an exception with text saying the specified property is not supported if the ServerVersion major version for this object is below 14.0 (SQL 2017)

(Inherited from SqlSmoObject)
ThrowIfBelowVersion80(String)

Throws an exception if the ServerVersion major version for this object is below 8.0 (SQL 2000)

(Inherited from SqlSmoObject)
ThrowIfBelowVersion80SP3()

Throws an exception if the ServerVersion for this object is below 8.760 (8.0 SP3)

(Inherited from SqlSmoObject)
ThrowIfBelowVersion90(String)

Throws an exception if the ServerVersion major version for this object is below 9.0 (SQL 2005)

(Inherited from SqlSmoObject)
ToString() (Inherited from SqlSmoObject)
Touch()

Mark the object "touched" for unconditional scripting of Alter.

(Inherited from SqlSmoObject)
TouchImpl()

Virtual method to allow derived classes to do additional work when touched.

(Inherited from SqlSmoObject)
UnbindDefaultImpl(Boolean) (Inherited from SqlSmoObject)
UnbindRuleImpl(Boolean) (Inherited from SqlSmoObject)
Validate(String, Object[]) (Inherited from SmoObjectBase)

Events

PropertyChanged (Inherited from SqlSmoObject)
PropertyMetadataChanged (Inherited from SqlSmoObject)

Explicit Interface Implementations

IAlienObject.Discover() (Inherited from SqlSmoObject)
IAlienObject.GetDomainRoot() (Inherited from SqlSmoObject)
IAlienObject.GetParent() (Inherited from SqlSmoObject)
IAlienObject.GetPropertyType(String)

Discovers type of property.

(Inherited from SqlSmoObject)
IAlienObject.GetPropertyValue(String, Type)

Retrieves value for a given property. Throws if property is not found.

(Inherited from SqlSmoObject)
IAlienObject.GetUrn() (Inherited from SqlSmoObject)
IAlienObject.Resolve(String) (Inherited from SqlSmoObject)
IAlienObject.SetObjectState(SfcObjectState)

Sets state of this object based on provided SfcObjectState.

(Inherited from SqlSmoObject)
IAlienObject.SetPropertyValue(String, Type, Object)

Sets the value of given property, if it is writable. If property is not in property bag, reflection is used. Throws exception if the property is not found.

(Inherited from SqlSmoObject)
ISfcPropertyProvider.GetPropertySet() (Inherited from SqlSmoObject)

Extension Methods

GetAssessmentItems(AvailabilityGroup, String[])

Finds all available checks for given availabilityGroup.

GetAssessmentItems(SqlSmoObject, String[])

Finds all available checks for given smoObject.

GetAssessmentResults(AvailabilityGroup, IEnumerable<ICheck>)

Synchronously runs assessment for given availabilityGroup and gives a IEnumerable<T> describing discovered issues. This method performs only given checks from checks.

GetAssessmentResults(AvailabilityGroup, String[])

Synchronously runs assessment for given availabilityGroup and gives a IEnumerable<T> describing discovered issues.

GetAssessmentResults(SqlSmoObject, IEnumerable<ICheck>)

Synchronously runs assessment for given smoObject and gives a IEnumerable<T> describing discovered issues. This method performs only given checks from checks.

GetAssessmentResults(SqlSmoObject, String[])

Synchronously runs assessment for given smoObject and gives a IEnumerable<T> describing discovered issues.

GetAssessmentResultsList(AvailabilityGroup, IEnumerable<ICheck>)

Synchronously runs assessment for given availabilityGroup and gives a IEnumerable<T> describing discovered issues. This method performs only given checks from checks.

GetAssessmentResultsList(AvailabilityGroup, String[])

Asynchronously runs assessment for given availabilityGroup and gives a List<T> describing discovered issues.

GetAssessmentResultsList(SqlSmoObject, IEnumerable<ICheck>)

Asynchronously runs assessment for given smoObject and gives a List<T> describing discovered issues. This method performs only given checks from checks.

GetAssessmentResultsList(SqlSmoObject, String[])

Asynchronously runs assessment for given smoObject and gives a List<T> describing discovered issues.

IsSupportedObject<T>(SqlSmoObject, ScriptingPreferences)

Checks if the specified type is supported by the ServerVersion and DatabaseEngineType of the root server for this object. If ScriptingPreferences are non-null will also check if specified type is supported by the ServerVersion and DatabaseEngineType of the target server.

Applies to