2017-03-09 67 views
0

在构建期间,我们根据SSDT .sql项目生成我们数据库的dacpac文件。这个dacpac稍后将使用sqlpackage部署到生产环境。 尽管使用/ p:DropStatisticsNotInSource = False开关,sqlpackage将删除所有统计信息,这些统计信息是在生产数据库的sqlproject的上次同步之后添加的。SSDT/SqlPackage丢弃统计信息

我们也可以重现此使用发布配置和生成SSDT的脚本选项:

<?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不要掉落统计?

+0

实际验证是检查生成的脚本,而不是传递给它的参数。剧本是做什么的? 'DropObjectsNotInSource'是否故意设置为'True'? –

+1

您是否在部署服务器上运行最新版本的sqlpackage.exe(dacfx)? – ErikEJ

+0

@PanagiotisKanavos是的,我们实际上想要在我们的数据库中删除表格,列和存储过程。 我正在运行安装了最新SSDT的VS2015,并尝试过VS2017。两者都产生相同的迁移脚本(使用DROP STATISTICS xyz.abc) –

回答

2

问题是使用DropObjectsNotInSource=True,它会覆盖DropStatisticsNotInSource=False选项。这是一个错误,或者在sqlpackage.exe文档中未指定。

一种可能的解决方法是使用Ed的AgileSqlClub SSDT过滤器 Elliott如this blog中所述。在这种情况下,您需要使用AgileSqlClub.SqlPackageFilter.dll,并添加以下选项:

/p:AdditionalDeploymentContributors=AgileSqlClub.DeploymentFilterContributor /p:AdditionalDeploymentContributorArguments="SqlPackageFilter=IgnoreType(Statistics)"