locked
Specifing sqlcmd variable values when using sqlpackage.exe RRS feed

  • Question

  • Hi,

    I am using sqlpackage.exe to try and publish my project. I have a sqlcmd variable called $(Id_value) and I want to supply a value for it. The following:

    >"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Microsoft SQL Server Data
    Tools\sqlpackage.exe" /TargetDatabaseName:MyDB /TargetServerName:".\RC0" /Action
    :Publish /SourceFile:"C:\Users\jamie\Documents\Visual Studio 2010\Projects\SSDT\
    TestRequiredSqlCmdVars\TestRequiredSqlCmdVars\bin\Debug\TestRequiredSqlCmdVars.d
    acpac" /p:Id_value=1

    fails with:

    *** 'Id_value' is not a valid argument for the 'Publish' action.

    Please could someone tell me ow to specify a value for a sqlcmd variable?

    thanks
    Jamie


    ObjectStorageHelper<T> – A WinRT utility for Windows 8 | http://sqlblog.com/blogs/jamie_thomson/ | @jamiet | About me
    Jamie Thomson

    Sunday, February 12, 2012 11:44 AM

Answers

All replies

  • Never mind, I found it: http://msdn.microsoft.com/en-us/library/hh550080(v=vs.103).aspx

    SQL Command Variables

    The following table describes the format of the option that you can use to override the value of a SQL command (sqlcmd) variable used during a publish action. The values of variable specified on the command line override other values assigned to the variable (for example, in a publish profile).

    Parameter Default Description

    /v: SQLCommandVariableName = value

    N/A

    Required if /Action:Publish is specified.

    You guys changed the syntax. It used to be /p: not /v:  :)


    ObjectStorageHelper<T> – A WinRT utility for Windows 8 | http://sqlblog.com/blogs/jamie_thomson/ | @jamiet | About me
    Jamie Thomson

    • Marked as answer by Janet Yeilding Monday, February 13, 2012 4:01 AM
    Sunday, February 12, 2012 11:46 AM
  • Thanks Jamie. Your answer helped me.

    Continuing to Jamie's answer, if we have multiple SQLCMD variables, we can use multiple /v: switches.


    - Chintak (My Blog)

    Thursday, September 18, 2014 10:54 AM
  • Thank you, Chintak! I've been looking for doco on how to provide multiple variables, and your post was the only answer I found!
    Monday, September 19, 2016 8:36 AM
  • Here is the syntax sugar for MULTIPLE SQLCMD variable values.

    SqlPackage.exe (other stuff pointing to dacpac)       /Variables:MyVariableOne="MyValueOne" /Variables:MyVariableTwo="MyValueTwo" /Variables:MyVariableThree="MyValueThree" 

    Tuesday, August 21, 2018 9:18 PM