I'm trying to use SQL Server Management Objects (SMO) to retrieve an extended property on an index, but the retrieved SMO object has an empty ExtentedProperties collection. (The index is on a table.) The extended property is there, I checked in T-SQL. Also, extended properties, e.g. on the database object are found by SMO. All I'm doing is
Server s = new Server(<connectionObj>);
Database db = s.Databases[<databaseName>];
int extCount = db.Tables[<tableName>]
.Indexes[<indexName>]
.ExtendedProperties
.Count
To get
extCount == 0
Am I doing it wrong?
Cheers,
Tilman
PS: It's SQL Server 2005
You need to refresh the collections before you can reference their items by name - I know - its weird.
Try:
Server s = new Server(<connectionObj>);
Database db = s.Databases[<databaseName>];
db.Tables.Refresh();
db.Tables[<tableName>].Indexes.Refresh();
int extCount = db.Tables[<tableName>]
.Indexes[<indexName>]
.ExtendedProperties
.Count