Powershell SQLCMD

怎甘沉沦 提交于 2019-12-06 11:43:58

问题


We were experiencing problems with Powershell and SQLCMD, when there was sapces in the -v parameter variable powershell wouldn't run the command.

e.g.

sqlcmd ... -v VAR="Some space"

Has anyone experienced this before or know how to fix the problem?

Thanks,

B


回答1:


The syntax above works for the PS commandline but fails within a script.

We struggled a long time with how to make this work. One of our very clever QA guys finally came up with the following:

$variableWithSpaces="one two three"
$mySqlCmd = "sqlcmd -E -S $dbServer -i $script  -v var=```"$variableWithSpaces```" "
Invoke-Expression $mySqlCmd 

Plug ugly but it works.




回答2:


Powershell will actually pass the parameter to the program as "VAR=Some space". Maybe sqlcmd stumbles over this. By using

VAR=`"Some space`"

instead it will get passed as VAR="Some space". Maybe that resolves the problem.



来源:https://stackoverflow.com/questions/1015038/powershell-sqlcmd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!