共用方式為


SqlSmoObject Class

Definition

Contains common functionality for all the instance classes

[System.ComponentModel.TypeConverter(typeof(Microsoft.SqlServer.Management.Sdk.Sfc.LocalizableTypeConverter))]
public abstract class SqlSmoObject : Microsoft.SqlServer.Management.Smo.SmoObjectBase, Microsoft.SqlServer.Management.Common.IRefreshable, Microsoft.SqlServer.Management.Sdk.Sfc.IAlienObject, Microsoft.SqlServer.Management.Sdk.Sfc.ISfcPropertyProvider, System.ComponentModel.INotifyPropertyChanged
[<System.ComponentModel.TypeConverter(typeof(Microsoft.SqlServer.Management.Sdk.Sfc.LocalizableTypeConverter))>]
type SqlSmoObject = class
    inherit SmoObjectBase
    interface ISfcPropertyProvider
    interface ISfcNotifyPropertyMetadataChanged
    interface INotifyPropertyChanged
    interface IRefreshable
    interface IAlienObject
Public MustInherit Class SqlSmoObject
Inherits SmoObjectBase
Implements IAlienObject, INotifyPropertyChanged, IRefreshable, ISfcPropertyProvider
Inheritance
SqlSmoObject
Derived
Attributes
Implements

Constructors

SqlSmoObject()

Fields

m_ExtendedProperties
singletonParent

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

Properties

DatabaseEngineEdition

Returns the DatabaseEngineEdition of the SMO object

DatabaseEngineType

Returns the DatabaseEngineType of the SMO object

ExecuteForScalar
ExecutionManager
IsTouched

Whether the object has been touched for unconditional scripting of Alter

ObjectInSpace
ParentCollection

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

Properties
ScalarResult
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.

State

Returns the state of the object

(Inherited from SmoObjectBase)
Urn

Returns the Urn of the object, computed on the fly

UserData (Inherited from SmoObjectBase)

Methods

AddDatabaseContext(StringCollection)

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

AlterImpl()
AlterImplWorker()
BindDefaultImpl(String, String, Boolean)
BindRuleImpl(String, String, Boolean)
CheckObjectState()
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

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

CleanObject()
CreateImpl()
CreateOrAlterImpl()
Discover()

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

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.

DropImpl(Boolean)

drops the object

DropImplWorker(Urn, Boolean)

drops the object

ExecuteNonQuery(StringCollection, Boolean, Boolean)

Executes sql statements

ExecuteWithModes(SqlExecutionModes, Action)

Executes the given action under the given execution modes.

Resets the original modes after the action completes or fails.

FormatSqlVariant(Object)
GenerateAlterEvent()
GenerateAlterEvent(Urn, Object)
GetChildType(String, String)
GetContextDB()
GetDBName()
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.

GetFragOptionString(FragmentationOption)
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.

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)

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.

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)

GetRealValue(Property, Object)

Returns the real value for the property.

GetServerName()
GetServerObject()
GetSqlServerVersionName()

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

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

GetTypeFromUrnSkeleton(Urn)
GetUrnRecursive(StringBuilder, UrnIdOption)

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

GetUrnRecursive(StringBuilder)

Computes the Urn for the object.

GetUrnSuffix(Type)

Gets the UrnSuffix from the specified type - or an empty string if the type does not define a static property named UrnSuffix.

ImplInitialize(String[], OrderBy[])
InitChildCollection(Urn, Boolean)

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

Initialize()
Initialize(Boolean)

Initializes the object, by reading its properties from the enumerator

IsCollectionDirty(ICollection)
IsExpressSku()

Returns whether the server containing this object is an Express SKU

IsObjectDirty()
IsObjectInitialized()
IsObjectInSpace()
IsSupportedOnSqlAzure(Type)

Returns whether a smo object type is supported on Microsoft Azure SQL Database.

IsSupportedProperty(String)

Validate whether the specified property is supported in current server environment

IsVersion80SP3()
IsVersion90AndAbove()
MakeSqlString(String)

Returns a fully-escaped SQL string wrapped within the SQL string single-quotes

MarkDropped()
MarkForDropImpl(Boolean)
PostAlter()

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

PostCreate()

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

PostDrop()

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

QuoteString(String, Char, Char)

Return name enclosing with delimiters.

Refresh()

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

ScriptImpl()
ScriptImpl(ScriptingOptions)

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

SetAccessToken(IRenewableToken)

Set the accessToken for connection.

SetParentImpl(SqlSmoObject)
SetState(SqlSmoState)

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

(Inherited from SmoObjectBase)
SqlDateString(DateTime)

Converts a DateTime to a string in a format that is unambiguous and can be converted into a sql datetime in T-SQL code regardless of the server's language setting.

SqlString(String)

Escapes all single-quotes in a string

ThrowIfAboveVersion100(String)

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

ThrowIfAboveVersion80(String)

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

ThrowIfBelowVersion100(String)

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

ThrowIfBelowVersion110(String)

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

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)

ThrowIfBelowVersion120(String)

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

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)

ThrowIfBelowVersion130(String)

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

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)

ThrowIfBelowVersion140(String)

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

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)

ThrowIfBelowVersion80(String)

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

ThrowIfBelowVersion80SP3()

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

ThrowIfBelowVersion90(String)

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

ToString()
Touch()

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

TouchImpl()

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

Trace(String)
UnbindDefaultImpl(Boolean)
UnbindRuleImpl(Boolean)
UpdateCollectionState2(ICollection)
Validate(String, Object[]) (Inherited from SmoObjectBase)

Events

PropertyChanged
PropertyMetadataChanged
PropertyMissing

Event that is raised when a property fetch is made after object initialization and the object needs to issue a SQL query to retrieve the value. This event is raised synchronously, so the fetch is blocked until all handlers of the event return.

Explicit Interface Implementations

IAlienObject.Discover()
IAlienObject.GetDomainRoot()
IAlienObject.GetParent()
IAlienObject.GetPropertyType(String)

Discovers type of property.

IAlienObject.GetPropertyValue(String, Type)

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

IAlienObject.GetUrn()
IAlienObject.Resolve(String)
IAlienObject.SetObjectState(SfcObjectState)

Sets state of this object based on provided SfcObjectState.

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.

ISfcPropertyProvider.GetPropertySet()

Extension Methods

GetAssessmentItems(SqlSmoObject, String[])

Finds all available checks for given smoObject.

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