[从Azure Pipeline使用SqlPackage部署DACPAC会忽略参数并删除用户

问题描述 投票:1回答:1

我在Azure中有一个发布管道,我在其中传递了一个.dacpac构件(使用VStudio创建),该构件将部署在本地Sql Server 2016中。它很好,但是现在我想删除表,视图,函数和存储.dacpac在我的服务器上进行操作。因此,我在VS项目中做到了这一点,然后尝试与选项/p:DropObjectsNotInSource=True以及/p:DoNotDropObjectType甚至/p:ExcludeObjectType一起部署,以排除我不想删除的内容。

但是不管这些过滤器如何,一旦作业开始,表将被删除(如预期的那样),但是随后它将删除数据库用户。它还会删除我用于安装Azure代理的登录名的db_owner映射,然后尝试删除该登录名(该用户与部署期间配置为进行身份验证的用户相同)。然后失败,并显示此错误:

Error SQL72014: .Net SqlClient Data Provider: Msg 15151, Level 16, State 1, Line 1 Cannot drop the user '<Domain>\<User>', because it does not exist or you do not have permission.

这很明显,因为刚刚删除了用户对数据库的许可。有什么建议可以避免这种情况,或者我唯一的选择是在完成后重新创建用户/权限?还是不完全使用该标志,而是通过部署后脚本执行所有“放置对象管道”?

作为参考,在我的发布任务上设置的其他参数是(看起来很奇怪,但是无法仅指定要删除的对象):

/p:DropObjectsNotInSource=True /p:BlockOnPossibleDataLoss=false /p:DoNotDropObjectType="Aggregates,ApplicationRoles,Assemblies,AsymmetricKeys,BrokerPriorities,Certificates,ColumnEncryptionKeys,ColumnMasterKeys,Contracts,DatabaseRoles,DatabaseTriggers,Defaults,ExtendedProperties,ExternalDataSources,ExternalFileFormats,ExternalTables,Filegroups,FileTables,FullTextCatalogs,FullTextStoplists,MessageTypes,PartitionFunctions,PartitionSchemes,Permissions,Queues,RemoteServiceBindings,RoleMembership,Rules,SearchPropertyLists,SecurityPolicies,Sequences,Services,Signatures,SymmetricKeys,Synonyms,UserDefinedDataTypes,UserDefinedTableTypes,ClrUserDefinedTypes,Users,XmlSchemaCollections,Audits,Credentials,CryptographicProviders,DatabaseAuditSpecifications,DatabaseScopedCredentials,Endpoints,ErrorMessages,EventNotifications,EventSessions,LinkedServerLogins,LinkedServers,Logins,Routes,ServerAuditSpecifications,ServerRoleMembership,ServerRoles,ServerTriggers" /p:ExcludeObjectType="Aggregates,ApplicationRoles,Assemblies,AsymmetricKeys,BrokerPriorities,Certificates,ColumnEncryptionKeys,ColumnMasterKeys,Contracts,DatabaseRoles,DatabaseTriggers,Defaults,ExtendedProperties,ExternalDataSources,ExternalFileFormats,ExternalTables,Filegroups,FileTables,FullTextCatalogs,FullTextStoplists,MessageTypes,PartitionFunctions,PartitionSchemes,Permissions,Queues,RemoteServiceBindings,RoleMembership,Rules,SearchPropertyLists,SecurityPolicies,Sequences,Services,Signatures,SymmetricKeys,Synonyms,UserDefinedDataTypes,UserDefinedTableTypes,ClrUserDefinedTypes,Users,XmlSchemaCollections,Audits,Credentials,CryptographicProviders,DatabaseAuditSpecifications,DatabaseScopedCredentials,Endpoints,ErrorMessages,EventNotifications,EventSessions,LinkedServerLogins,LinkedServers,Logins,Routes,ServerAuditSpecifications,ServerRoleMembership,ServerRoles,ServerTriggers"

sql-server azure-devops azure-pipelines dacpac sqlpackage
1个回答
0
投票

所以,我对自己说:我最初的尝试有两件事是错误的:

  • 当您想在参数中使用多个值时,必须用分号(;)代替冒号。
  • 如果要排除多个对象,则参数名称必须为复数形式:/p:ExcludeObjectTypes

所以,通过以下类似的操作,我实现了我想要的:

/p:ExcludeObjectTypes=Users;Logins;RoleMembership;Permissions;Credentials;DatabaseScopedCredentials

© www.soinside.com 2019 - 2024. All rights reserved.