Cannot access properties of index in an SMO index collection.

I am looping through the indexes of a table stored in SQL 2000 by using SMO.  Some properties cannot be accessed such as "IsSystemObject".  It gives me a PropertyNotSetException.  Since I'm looping through existing indexes on the table, why can't I access some properties of each index



Answer this question

Cannot access properties of index in an SMO index collection.

  • Bhawna

    I am guessing, but are you trying to see whether a Table has system generated Statistics (also called sometimes what-if indexes)

    If that is the case, take a look at the Statistic.IsAutoCreated property. I am betting this is what you are looking for.

    Also, take a look at this sample I just posted. The sample shows how to test which SQL Server versions is supported by a property.

    If you can BTW show a code snippet that demonstrates the issue you have with IsSystemObject that will be appreciated. I suspect it is a bug.

    Thanks!


  • batmc

    SMO exposes a union of all properties for the object available on all supported servers, so on downlevel servers you sometimes get exceptions when you access properties that are not available on that server. 

    You have to make sure you only get the properties that are supported on that particular server.  Alternatively, you can wrap your property accesses with an exception handler and handle the case when you try to get an unsupported property.

    In the case of IsSystemObject, there is no such thing as a "system index" in SQL Server, so it should be getting whether the parent table is a system table.  If you get "IsSystemObject" on the parent table, do you see the expected value, or an error

  • arghhhhhh

    Thanks for the response.  After reading your post, I realize that I am probably using "IsSystemObject" incorrectly.  What I am really trying to figure out is if the index is generated automatically by SQL (and not one that I intentionally created).  I thought mayby "IsSystemObject" would tell me that.  Besides using a certain naming convention check, is there any property available on the index object that tells me it was created by SQL server (statistical index, etc...)
  • Cannot access properties of index in an SMO index collection.