Is there any way to stop SqlPackage.exe setting default Filegroup in deployment script?

允我心安 提交于 2020-01-02 03:00:12

问题


We are using Sql Server database projects to create deployment scripts from DacPac using SqlPackage.exe. We have different SQL Server Filegroups setup in various environments. When deploying we exclude Filegroups as we want objects to create in the default Filegroup. In database project settings the default Filegroup is not changed from PRIMARY.

This presents a problem when attempting to deploy to an environment where the default Filegroup is not PRIMARY because the following code is included...

ALTER DATABASE [$(DatabaseName)]
    MODIFY FILEGROUP [PRIMARY] DEFAULT;

Is there a way to prevent this from generating in the deployment SQL?


回答1:


I don't know if you can disable it within SSDT.

But you can use deployment plan contributor to filter out MODIFY FILEGROUP statement or to change it the way you want. You can find detailed instructions and working code here: http://scardevblog.blogspot.com/2015/03/ssdt-generates-2012-option-for-target.html




回答2:


When you generate the dacpac file from SSDT in SQL Server Management Studio you can't choose you type of objects you extract to the dacpac.

But when you run sqlpackage.exe via command line there is a parameter you could use.

sqlpackage.exe your_deploy_options /p:ExcludeObjectTypes=Filegroups

This will ignore the deployment of filegroups. See this reference for the full options: https://msdn.microsoft.com/en-us/library/hh550080(v=vs.103).aspx

If you have Visual Studio, then you can import your database as a database project in VS and there remove the filegroups from the scripts, so when you deploy/compare schemas they wouldn't be compared.



来源:https://stackoverflow.com/questions/42498706/is-there-any-way-to-stop-sqlpackage-exe-setting-default-filegroup-in-deployment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!