microsoft / sqlmanagementobjects

Sql Management Objects, an API for scripting and managing SQL Server and Azure SQL Database
Other
130 stars 21 forks source link

Extended properties not supported on Azure Sql? Is there a plan to support? #178

Open ScottyTarvan opened 4 days ago

ScottyTarvan commented 4 days ago

Hi all,

Im using SMO to generate a database and related objects on an Azure Sql server (fully hosted not a VM or Sql Managed Instance). I can generate objects such as tables, indexes, stored procedures and views but I cannot create extended properties associated with these objects. This works perfectly on my local sql server. As a result of this problem I have had to add my own extended property script generators which has exploded the code base. Any plans to correct this in the future?

Thanks

shueybubbles commented 4 days ago

Double check how you set your scripting options. I enable "Script extended properties" in SSMS in "Tools/Options/SQL Server Object Explorer/Scripting" and when I "Script Table As Create" in OE it includes EP scripts

I can cross script from SQL Server to Azure SQL Database too, and it includes EPs

Image

ScottyTarvan commented 18 hours ago

Im using the SMO objects in code only, not in SSMS or Azure Data Studio. There is an inconsistent deployment of extended properties for different objects. For tables it will create the extended properties but for other objects like views, stored procedures, indexes it does not create them. Ill investigate the options you mention above and see if that makes a difference.

ScottyTarvan commented 13 hours ago

I have managed to get this to work by executing the SMO extended property after I create the object. This is different behaviour from tables that create the extended properties at the same time as table creation.

Eg.

//create SMO procedure in code not shown

var smoProperty = new SMOProperty(smoProcedure, "InstanceId", asset.InstanceId.ToString());
smoProcedure.ExtendedProperties.Add(smoProperty);

//does not create EP
smoProcedure.Create();

//have to run this to create EP
smoProperty.Create();
shueybubbles commented 7 hours ago

I see. I misread the original issue to mean you were trying to generate scripts from an existing database. It's a weird difference in behavior. At this point, though, it's probably more risky to fix it than to leave it as-is. There are probably other apps that directly or indirectly depend on the current behavior.