转义SQLCMD特殊符号 [英] Escaping special symbols in Sqlcmd

查看:717
本文介绍了转义SQLCMD特殊符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,当我安装我的应用程序,它执行一串SQL脚本的一个bat文件。在安装对话框用户设置DBNAME,登录和密码,然后在此bat文件中。在这里,它是:

I have a bat file which executes bunch of sql scripts when i install my application. In installation dialogs user sets dbname, login and password which are then used in this bat file. Here it is:

SET _server="(local)"
SET _db=dbname
SET _user=sa
SET _pswr="!#$%^&*()<>"

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regsql.exe -S %_server% -d %_db% -U %_user% -P %_pswr% -A all

"%systemdrive%\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.exe" -S %_server% -d %_db% -U %_user% -P %_pswr% -i .\createDB.sql

pause

一切,直到密码不包含任何特殊符号的伟大工程。但是,如果这样做我得到以下错误登录失败,用户'山'。所以很明显,那你心中已错密码。而现在的问题是:我如何能在bat文件逃避这些特殊符号

Everything works great until password doesn't contain any special symbols. But if it does i get following error "Login failed for user 'sa'.". So it's obvious, that somethins wrong with password. And now the question: How can i escape these special symbols in bat file?

PS:
我试图取代:

PS: I tried replacing:

< - &lt;
> - &gt;
& - &amp;

但它并不能帮助。

But it doesn't help.

谢谢!

推荐答案

您需要通过他们加倍逃脱百分号(%)字符和符号(^)字符。这里是有问题的命令行字符的列表

You need to escape the percent (%) character and the caret(^) character by doubling them. Here is a list of problematic command line characters

SET _pswr="!#$%%^^&*()<>"

这篇关于转义SQLCMD特殊符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆