Freigeben über


SMO Sample: Which SQL Server version is supported by the property?

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).

Server svr = new Server(instance);

Database db = svr.Databases[0];

foreach (SqlPropertyInfo i in db.Properties.EnumPropertyInfo())
{
   Console.WriteLine("{0,-35} {1,-25} {2}", i.Name, i.PropertyType.Name, i.Versions.ToString().Replace("Version", ""));
}

Partial output:

PrimaryFilePath String 70, 80, 90
ReplicationOptions ReplicationOptions 70, 80, 90
Size Double 70, 80, 90
SpaceAvailable Double 70, 80, 90
Status DatabaseStatus 70, 80, 90
UserName String 70, 80, 90
CaseSensitive Boolean 80, 90
Collation String 80, 90
IsUpdateable Boolean 80, 90
Version Int32 80, 90
AutoCreateStatisticsEnabled Boolean 90
AutoUpdateStatisticsEnabled Boolean 90
DatabaseGuid 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.

Comments

  • Anonymous
    June 15, 2006
    bit of an aside , you state "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"

    this doesn't seem to be reflected in a lot of the documentation - I've seen a lot of (post RTM) presentations that say SMO is supported against 7.0

    namely BOL

    http://msdn2.microsoft.com/en-us/library/ms162557.aspx

    (yes I have fed this back :-)