SqlCmd :用变量和反斜杠连接
当使用 SqlCmd 尝试连接到活动服务器时,我发现这两种方法都有效:
:connect myServer\myInstanceName -U myLogin -P myPassword
:setvar INSTANCE myInstanceName
:connect $(INSTANCE) -U myLogin -P myPassword
这不起作用:
:setvar serv myServer
:setvar inst myInstance
:connect $(serv)\$(inst) -U myLogin -P myPassword
它将此作为语法错误抛出,我怀疑是因为它认为反斜杠是转义字符。
这样做没有帮助:
:connect '$(serv)\$(inst)' -U myLogin -P myPassword
而且这也没有帮助:
:connect $(serv)\\\\$(inst) -U myLogin -P myPassword
而且我无法弄清楚 sqlCmd 应该如何连接变量,所以我无法将整个事情作为变量传递。如果您尝试设置这样的变量:
:setvar serv myServer
:setvar myVariable $(serv)\
那么它实际上将 myVariable 设置为“$(serv)\”,这并没有多大帮助。
有人帮忙吗?
When using SqlCmd to try and connect to an active server I have discovered that these both work:
:connect myServer\myInstanceName -U myLogin -P myPassword
:setvar INSTANCE myInstanceName
:connect $(INSTANCE) -U myLogin -P myPassword
This does not:
:setvar serv myServer
:setvar inst myInstance
:connect $(serv)\$(inst) -U myLogin -P myPassword
It throws this as a syntax error, I suspect because it thinks the back-slash is an escape character.
Doing this doesn't help:
:connect '$(serv)\$(inst)' -U myLogin -P myPassword
And neither does this:
:connect $(serv)\\\\$(inst) -U myLogin -P myPassword
And I can't figure out how sqlCmd is supposed to concatenate variables, so I can't pass the whole thing in as a variable. If you try and set a variable like this:
:setvar serv myServer
:setvar myVariable $(serv)\
Then it literally sets myVariable to be "$(serv)\" which isn't a lot of help.
Anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你能不能使用类似的东西
Can you not use something like
我发现的最佳解决方案是使用 powershell 或 DOS 脚本设置变量。
The best solution I've found to this is to set the variables using powershell or DOS scripts.