Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use multiple SQLCMD variables with SqlPackage.exe while deploying a DacPac?

I am deploying a dacpac using sqlpackage.exe and need to pass SqlCMD variables for a postdeployment script in the dacpac. I found a related question here and here.

But i am getting the following error: Missing values for the following SqlCmd variables:BuildVersion Description. Description=$Description : The term 'Description=$Description' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Please help me.

like image 572
user2082197 Avatar asked May 20 '26 18:05

user2082197


2 Answers

The correct switch for passing a SQLCMD variable to SQLPackage is like this /v:Description=$Description

Powershell quoting is a bit tricky. Here's an example for you:

https://gist.github.com/davoscollective/adf9b890984e51d8dee2

& "C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\sqlpackage.exe" ` #Note this is SQL Server 2012 specific directory, alter as needed
/Action:Publish `
/SourceFile:$sourceFile `
/TargetServerName:$targetServerName `
/TargetDatabaseName:$targetDBname `
/V:SQLCMDVariable1=$SQLCMDVariable1 ` #If your project includes other database references, or pre/post deployment scripts uses SQLCMD variables
/v:SQLCMDVariable2=$SQLCMDVariable2 `
like image 172
Davos Avatar answered May 23 '26 08:05

Davos


It seems like you are using Powershell to call SqlPackage based on the cmdlet error. If this is the case ensure the Dollar symbols are escaped with a inverted apostrophe i.e.

ie Description=`$Description

Could you post the full command you are passing?

like image 43
Eugene Niemand Avatar answered May 23 '26 07:05

Eugene Niemand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!