Partager via


Setting Properties

Properties are values that store descriptive information about the object. For example, Microsoft SQL Server configuration options are represented by the Configuration object's properties. Properties can be accessed either directly or indirectly by using the property collection. Accessing properties directly uses the following syntax:

objInstance.PropertyName

A property value can be modified or retrieved depending on whether the property has read/write access or read-only access. It is also necessary to set certain properties before an object can be created. For more information, see the SMO reference for the particular object.

ms162187.note(fr-fr,SQL.90).gifRemarque :
Collections of child objects appear as the property of an object. For example, the Tables collection is a property of a Server object. For more information, see Using Collections.

The properties of an object are members of the Properties collection. The Properties collection can be used to iterate through every property of an object.

Sometimes a property is not available for the following reasons:

The server version does not support the property, such as if you try to access a property that represents a new Microsoft SQL Server 2005 feature on an older version of Microsoft SQL Server. The server does not provide data for the property, such as if you try to access a property that represents a SQL Server component that is not installed.

You can handle these circumstances by catching the UnknownPropertyException and the PropertyCannotBeRetrievedException SMO exceptions.

Setting Default Initialization Fields

SMO performs an optimization when retrieving objects. The optimization minimizes the number of properties loaded by automatically scaling between the following states:

  1. Partially loaded. When an object is first referenced it has a minimum of properties available (such as Name and Schema).
  2. Fully loaded. When any property is referenced, the remaining properties that are quick to load, are initialized and are made available.
  3. Properties that use lots of memory. The remaining unavailable properties use lots of memory and have an Expensive property value of true (such as DataSpaceUsage). These properties are loaded only when specifically referenced.

If your application does fetch extra properties, besides the ones provided in the partially loaded state, it submits a query to retrieve these extra properties and scales up to the fully loaded state. This can cause unnecessary traffic between the client and server. More optimization can be achieved by calling the SetDefaultInitFields method. The SetDefaultInitFields method allows specification of the properties that are loaded when the object is initialized.

The SetDefaultInitFields method sets the property loading behavior for the rest of application or until it is reset. You can save the original behavior by using the GetDefaultInitFields method and restore it as required.

Voir aussi

Tâches

How to: Get and Set a Property in Visual Basic .NET
How to: Set Various Properties Before an Object is Created in Visual Basic .NET
How to: Iterate Through All Properties of an Object in Visual Basic .NET
How to: Set Default Initialization Fields in Visual Basic .NET

Concepts

Handling SMO Exceptions

Aide et Informations

Assistance sur SQL Server 2005