3

I'm running the below sqlpackage command against my sqlserver:

 sqlpackage /action:Publish /SourceFile:"Database Services\bin\Release\Database Services.dacpac" /TargetConnectionString:"Data Source=${Env};Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False;Initial catalog=${Target}"

It contains one predeploy script with one alter. However, I see in the error it tries to alter the whole DB (one level up) instead just doing the alter on the table. any idea why? does it related to some flags I need to add as mentioned here:

https://learn.microsoft.com/en-us/sql/tools/sqlpackage/sqlpackage-publish?view=sql-server-ver15#properties-specific-to-the-publish-action

arielma
  • 1,308
  • 1
  • 11
  • 29

1 Answers1

3

I would recommend using /action:Script (see here) to see which actions it will perform, most likely this will give you some clue as to which flags should be set/cleared.

-- Edit According to this old answer you can disable deploying the database properties when designing the .dacpac.
If you want to override this behaviour when publishing the .dacpac, you should probably use the ScriptDatabaseOptions property - see the whole list of switches here.

Leon Bouquiet
  • 4,159
  • 3
  • 25
  • 36
  • Tnx, you helped me focus on the real issue. Why this part was created and which flag can prevent it: `IF EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)') BEGIN ALTER DATABASE [$(DatabaseName)] SET ANSI_NULL_DEFAULT ON WITH ROLLBACK IMMEDIATE; END` – arielma Jun 15 '21 at 11:19
  • Tnx a lot! I'm able to understand now from where it came from. can I use your help for another unresolved question? https://stackoverflow.com/questions/67956360/sqlpackage-deployreport-generate-empty-xml – arielma Jun 15 '21 at 12:11