I am using the following command to generate to publish database changes using SSDT:
"C:\Program Files\Microsoft SQL Server\150\DAC\bin\SqlPackage.exe" /Action:Publish /sf:DB.dacpac /Profile:publish.xml
I would like to supply database connection string as an argument instead of using a hard coded connection string from publish.xml. Is there anyway I can override it?
I tried:
"C:\Program Files\Microsoft SQL Server\150\DAC\bin\SqlPackage.exe" /Action:Publish /sf:DB.dacpac /Profile:publish.xml /TargetConnectionString:$ConnectionString
where $ConnectionString is an argument from Jenkins. However, it still uses ConnectionString from publish.xml.
I had a quick look at the source code with reflector (Microsoft.Data.Tools.Schema.CommandLineTool.ValidationUtil) and what happens is that TargetConnectionString is read from the command line, then after that the value in the publish profile overwrites the value - that can't be changed I am afraid.
The interesting thing is that after it has the connection string from either /TargetConnectionString or the publish profile it then applies the individual properties such as /TargetDatabaseName so i think (untested but looks good from the code) if instead of passing /TargetConnectionString you pass the individual components such as:
/TargetUser, /TargetPassword, /TargetDatabaseName, /TargetServerName, etc.
Then I think it will override the connection string in the publish profile, it is quite hard to read so let me know how you get on!
ed