我们已经开始使用SSDT来管理脚本部署。最初,我们使用Schema Compare并取消选中了我们不想部署的部分。现在,我们需要使用仅包含在“发布”功能中的Pre-Deploy脚本和Post-Post脚本,并且我们还试图清除我们所排除的部分。
在发布中添加了2个差异,这些差异没有在“模式比较”中,即使设置与我设置的尽可能接近,我似乎也无法弄清。
首先是,即使DropStatisticsNotInSource
设置为false,发布脚本仍希望删除dacpac中不存在的表的统计信息。我能够根据SSDT/SqlPackage drops statistics中的DeploymentFilterContributor答案解决此问题。
第二个继续困扰我。大多数应用程序安全性是通过授予角色来实现的,并且取决于环境,使各个系统帐户成为成员,但是在dev数据库中,也没有角色的用户(通常是管理员,但具有各种权限的实用程序)。我们在不同的环境中有不同的用户。我的长期目标是仅让用户担任角色,但我们还没有。同时,我们需要将用户排除在外。我从设置Exclude Users
,ExcludeLogins
和ExcludeRoleMembership
开始,这是我们在“模式比较”中使用的,并且效果很好。但是,在“发布”脚本中,我们获得了REVOKE CONNECT
个脚本(但没有DROP LOGIN
或DROP USER
)。
我已经阅读了Prevent dropping of users when publishing a DACPAC using SqlPackage.exe和Create User in dacpac deployed by SqlPackage.exe leads to login failed SqlException(这似乎是一个类似的脚本结果,但目标不同,也没有答案)。我尝试将AgileSqlClub.DeploymentFilterContributor与IgnoreType(Login)
,IgnoreType(User)
,IgnoreType(RoleMembership)
以及IgnoreType(Permissions)
,IgnoreSecurity
一起使用。前3个无效。最后2个(我也尝试过等效的SSDT config选项)也删除了我想针对数据库角色添加的GRANT
脚本。
我觉得我应该能够执行此操作,而无需创建自定义DeploymentContributor
并且无需在部署后为所有这些用户编写脚本。如何摆脱这些REVOKE CONNECT
的电话?
另外,如果有人知道Visual Studio是否实际上在其路径中调用SqlPackage.exe或正在使用库,我将非常感激该信息...我似乎无法在我的5个SqlPackage.exe中得到任何一个机器可以与VS使用的内置.dacpac和.publish.xml文件一起使用。
我将提供完整的发布资料供参考:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AdditionalDeploymentContributors>AgileSqlClub.DeploymentFilterContributor</AdditionalDeploymentContributors>
<!--AdditionalDeploymentContributorArguments>SqlPackageFilter0=IgnoreType(Statistics);SqlPackageFilter1=IgnoreType(Login);SqlPackageFilter2=IgnoreType(User);SqlPackageFilter3=IgnoreType(RoleMembership);SqlPackageFilter4=IgnoreSchema(SEQUENCES)</AdditionalDeploymentContributorArguments-->
<!--AdditionalDeploymentContributorArguments>SqlPackageFilter4=IgnoreSchema(SEQUENCES)</AdditionalDeploymentContributorArguments-->
<AdditionalDeploymentContributorArguments>SqlPackageFilter0=IgnoreType(Statistics);SqlPackageFilter1=IgnoreSecurity</AdditionalDeploymentContributorArguments>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>BRM</TargetDatabaseName>
<DeployScriptFileName>BRM.sql</DeployScriptFileName>
<TargetConnectionString>Data Source=mydb;Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True</TargetConnectionString>
<BlockOnPossibleDataLoss>True</BlockOnPossibleDataLoss>
<ExcludeAggregates>False</ExcludeAggregates>
<ExcludeApplicationRoles>False</ExcludeApplicationRoles>
<ExcludeAssemblies>True</ExcludeAssemblies>
<ExcludeAsymmetricKeys>True</ExcludeAsymmetricKeys>
<ExcludeBrokerPriorities>True</ExcludeBrokerPriorities>
<ExcludeCertificates>True</ExcludeCertificates>
<ExcludeExternalDataSources>True</ExcludeExternalDataSources>
<ExcludeExternalFileFormats>True</ExcludeExternalFileFormats>
<ExcludeExternalTables>True</ExcludeExternalTables>
<ExcludeFilegroups>True</ExcludeFilegroups>
<ExcludeFileTables>True</ExcludeFileTables>
<ExcludeFullTextCatalogs>True</ExcludeFullTextCatalogs>
<ExcludeFullTextStoplists>True</ExcludeFullTextStoplists>
<ExcludePartitionFunctions>True</ExcludePartitionFunctions>
<ExcludePartitionSchemes>True</ExcludePartitionSchemes>
<ExcludeQueues>True</ExcludeQueues>
<ExcludeRemoteServiceBindings>True</ExcludeRemoteServiceBindings>
<IgnoreRoleMembership>True</IgnoreRoleMembership>
<ExcludeRules>True</ExcludeRules>
<ExcludeSecurityPolicies>True</ExcludeSecurityPolicies>
<ExcludeServices>True</ExcludeServices>
<ExcludeSignatures>True</ExcludeSignatures>
<ExcludeUserDefinedDataTypes>True</ExcludeUserDefinedDataTypes>
<ExcludeUserDefinedTableTypes>True</ExcludeUserDefinedTableTypes>
<ExcludeUsers>True</ExcludeUsers>
<ExcludeXmlSchemaCollections>True</ExcludeXmlSchemaCollections>
<DropObjectsNotInSource>True</DropObjectsNotInSource>
<DropPermissionsNotInSource>False</DropPermissionsNotInSource>
<DropRoleMembersNotInSource>False</DropRoleMembersNotInSource>
<DisableAndReenableDdlTriggers>False</DisableAndReenableDdlTriggers>
<IncludeTransactionalScripts>True</IncludeTransactionalScripts>
<ProfileVersionNumber>1</ProfileVersionNumber>
<DropStatisticsNotInSource>False</DropStatisticsNotInSource>
<ExcludeLogins>True</ExcludeLogins>
<ExcludeAudits>True</ExcludeAudits>
<ExcludeClrUserDefinedTypes>True</ExcludeClrUserDefinedTypes>
<ExcludeCredentials>True</ExcludeCredentials>
<ExcludeCryptographicProviders>True</ExcludeCryptographicProviders>
<ExcludeDatabaseScopedCredentials>True</ExcludeDatabaseScopedCredentials>
<ExcludeDatabaseAuditSpecifications>True</ExcludeDatabaseAuditSpecifications>
<ExcludeEndpoints>True</ExcludeEndpoints>
<ExcludeErrorMessages>True</ExcludeErrorMessages>
<ExcludeEventSessions>True</ExcludeEventSessions>
<ExcludeLinkedServerLogins>True</ExcludeLinkedServerLogins>
<ExcludeLinkedServers>True</ExcludeLinkedServers>
<ExcludeRoutes>True</ExcludeRoutes>
<ExcludeSearchPropertyLists>True</ExcludeSearchPropertyLists>
<ExcludeServerAuditSpecifications>True</ExcludeServerAuditSpecifications>
<ExcludeServerRoleMembership>True</ExcludeServerRoleMembership>
<ExcludeServerRoles>True</ExcludeServerRoles>
<ExcludeServerTriggers>True</ExcludeServerTriggers>
<DoNotDropLogins>True</DoNotDropLogins>
<DoNotDropUsers>True</DoNotDropUsers>
<DoNotDropRoleMembership>True</DoNotDropRoleMembership>
<DoNotDropServerRoleMembership>True</DoNotDropServerRoleMembership>
</PropertyGroup>
<ItemGroup>
<SqlCmdVariable Include="mscrm">
<Value>mscrm</Value>
</SqlCmdVariable>
<SqlCmdVariable Include="sysdb">
<Value>sysdb</Value>
</SqlCmdVariable>
</ItemGroup>
</Project>
VS2015 Update 3和SSDT 14.0.61712.050(我认为是最新的)。
答案 0 :(得分:0)
因此,作为后续工作,我还没有令人满意地解决此问题,并且已经将其撤离了一段时间。我什至不确定在最新版本中它仍然是一个问题。但是,对于仍在研究此问题的任何人,这是我开始遵循混合结果的道路。我将它留给其他人继续。
我决定尝试直接调用sqlpackage.exe,事实证明,正如我记得的那样,这似乎可以解决此特定问题,但是后来遇到了其他问题。一些问题涉及与哪个SQL Server一起使用哪个版本的sqlpackage。无论如何,您都可以自己尝试一下,如果您希望在此处进行回复,或发布更完整的答案。
"<path to sqlpackage>\sqlpackage.exe" /a:script /pr:"MyDB.Publish.xml" /sf:"MyDB.dacpac" /dsp:"c:\temp\sqlpackage test\deploy.sql" /p:DropStatisticsNotInSource=False
同样,我会按原样提供,但是如果您的工作正常,请随时编辑答案或发布自己更完整的答案。
答案 1 :(得分:0)
将此添加到发布个人资料
<ExcludeUsers>True</ExcludeUsers>
<ExcludeLogins>True</ExcludeLogins>
<IgnorePermissions>True</IgnorePermissions>
<IgnoreRoleMembership>True</IgnoreRoleMembership>
答案 2 :(得分:0)
您可以在SSDT中创建用户语句后添加“ GRANT CONNECT TO [YourUser]”吗?它将覆盖吊销连接执行。
CREATE USER [YourUser] FOR EXTERNAL PROVIDER
GO
GRANT CONNECT TO [YourUser]
GO