Monday, March 19, 2012

Extended Properties

When I add an extended property using SMO, it doesn't show up on the Properties of the table in SQL Management Studio. Also, if I add one in Managment Studio, I can't see it using SMO. What am I missing here?

Can you please provide some more information on how you are trying to add and retrieve the Extended Properties using SMO. And also what version of SQL Server are you using.

Your code should look similar to -

Table t = mydb.Tables["tableName"];

foreach(ExtendedProperty exp in t.ExtendedProperties)

{

Console.WriteLine(exp.Name + " " + exp.Value);

}

t.ExtendedProperties.Add(new ExtendedProperty("propertyName", "property value"));

|||My code is pretty much just like that. I am using SQL Server 2005.|||

Here is the code sample which I found working, let me know if you face any issues.

Server server = newServer("localhost");

Table table = server.Databases["mydatabase"].Tables["mytable"];

table.ExtendedProperties.Add(newExtendedProperty(table, "propertyName", "propertyValue"));

table.Alter();

table.Refresh();

foreach (ExtendedProperty e in table.ExtendedProperties)

{

Console.WriteLine(e.Name + " " + e.Value.ToString());

}

Thanks,

Kuntal

No comments:

Post a Comment