Purpose of sample: List metadata information about SMO object properties
SMO's object model is different from DMO in one important way: DMO introduced the '2' (like Database2) objects in order to add SQL Server 2000 support. SMO objects are hybrid in that perspective, as these objects morph or limit behavior based on the SQL Server version they work with. This makes SMO objects somewhat harder to work with, as you need to know what properties are supported on a particular server version. With the right tools at hand the objects are actually easier to work with, and one important tool is the EnumPropertyInfo and GetPropertyInfo methods, as these allow checking the version support of a property.
This sample lists all properties, and the version information. There is more information available, such as: if a property is writeable (it is always readable), or if it is expensive (means that it will be retrieved on demand only, due to high cost).
Partial output:
PrimaryFilePath String 70, 80, 90ReplicationOptions ReplicationOptions 70, 80, 90Size Double 70, 80, 90SpaceAvailable Double 70, 80, 90Status DatabaseStatus 70, 80, 90UserName String 70, 80, 90CaseSensitive Boolean 80, 90Collation String 80, 90IsUpdateable Boolean 80, 90Version Int32 80, 90AutoCreateStatisticsEnabled Boolean 90AutoUpdateStatisticsEnabled Boolean 90DatabaseGuid Guid 90
The '70' entries are an artifact. These are left behind, as SMO was initially planning to support SQL Server 7.0. However, that support was dropped around Beta 1 time frame.
Disclaimer: this sample doesn't handle exceptions and may not function as expected. Use at own risk. It is good practice to test an application before using it in production.