在构建期间,我们基于SSDT .sqlproject生成数据库的dacpac文件。这个dacpac稍后将使用sqlpackage部署到生产环境中。尽管使用了/p:DropStatisticsNotInSource=False开关,sqlpackage仍将删除上次sqlproject与生产数据库同步后添加的所有统计信息。
我们也可以使用发布配置文件和SSDT的generate script选项来重现:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>hotel</TargetDatabaseName>
<DeployScriptFileName>Database.sql</DeployScriptFileName>
<TargetConnectionString>connectionstring</TargetConnectionString>
<BlockOnPossibleDataLoss>False</BlockOnPossibleDataLoss>
<DropObjectsNotInSource>True</DropObjectsNotInSource>
<DoNotDropDatabaseRoles>True</DoNotDropDatabaseRoles>
<DoNotDropDatabaseScopedCredentials>True</DoNotDropDatabaseScopedCredentials>
<DoNotDropUsers>True</DoNotDropUsers>
<DoNotDropServerRoles>True</DoNotDropServerRoles>
<DoNotDropSecurityPolicies>True</DoNotDropSecurityPolicies>
<DoNotDropSearchPropertyLists>True</DoNotDropSearchPropertyLists>
<DoNotDropPermissions>True</DoNotDropPermissions>
<DoNotDropPartitionSchemes>True</DoNotDropPartitionSchemes>
<DoNotDropPartitionFunctions>True</DoNotDropPartitionFunctions>
<DoNotDropExternalFileFormats>True</DoNotDropExternalFileFormats>
<DoNotDropExternalTables>True</DoNotDropExternalTables>
<DoNotDropErrorMessages>True</DoNotDropErrorMessages>
<DoNotDropDefaults>False</DoNotDropDefaults>
<ProfileVersionNumber>1</ProfileVersionNumber>
<DropStatisticsNotInSource>False</DropStatisticsNotInSource>
<ScriptRefreshModule>False</ScriptRefreshModule>
</PropertyGroup>
</Project>如何才能强制sqlpackage不丢弃统计信息?
发布于 2018-02-15 22:42:40
问题在于DropObjectsNotInSource=True的使用,它会覆盖DropStatisticsNotInSource=False选项。这可能是一个错误,或者没有在sqlpackage.exe文档中指定。
一种可能的解决方法是使用Ed Elliott的AgileSqlClub SSDT过滤器,如this blog中所述。在这种情况下,您需要使用AgileSqlClub.SqlPackageFilter.dll并添加以下选项:
/p:AdditionalDeploymentContributors=AgileSqlClub.DeploymentFilterContributor /p:AdditionalDeploymentContributorArguments="SqlPackageFilter=IgnoreType(Statistics)"
https://stackoverflow.com/questions/42691811
复制相似问题