I have asked this question on MSDN forum without any response. Maybe here someone could help me?
I think it's a bug in SSDT and quite old one. I've tried several versions of SSDT binaries but the problem persists. SQLPackage.exe doesn't exclude trigger properly especially if it is encrypted. The situation:
- Create simple table dbo.TheTable and encrypted trigger in empty database:
create table dbo.TheTable(Name varchar(30) not null); create trigger dbo.trgInsTheTable on dbo.TheTable with encryption for insert as print 'insert to TheTable';
- Use SQLPackage.exe and extract (Action:Extract) that database to dacpac:
SqlPackage.exe /Action:Extract /TargetFile:"DB.dacpac" /SourceDatabaseName:"DB" /SourceServerName:".\Sandbox"
- Run SQLPackage.exe to generate scripts (Action:Script), the same database can be used:
SqlPackage.exe /Action:Script /SourceFile:".\DB.dacpac" /Profile:".\Sandbox.Publish.xml" /p:CreateNewDatabase=True /OutputPath:".\DB.sql"
And following error is thrown:
Error SQL0: The element [dbo].[trgInsTheTable] cannot be deployed as the script body is encrypted.
- OK, now let's try to have just table TheTable generated and for that use /p:ExludeObjectTypes=DatabaseTriggers;ServerTriggers:
SqlPackage.exe /Action:Script /SourceFile:".\DB.dacpac" /Profile:".\Sandbox.Publish.xml" /p:CreateNewDatabase=True /OutputPath:".\DB.sql" /p:ExcludeObjectTypes=DatabaseTriggers;ServerTriggers
The above error is thrown again. The only but not acceptable way is to add Tables to ExludeObjectTypes. Then this trigger is excluded but together with table it is created on.
The publish XML file can be anything default.
What am I missing here?