sqlcmd通过WSH挂起jscript但不挂起vbscript

时间:2014-12-16 18:45:28

标签: vbscript jscript sqlcmd wsh

我有两个脚本,vbtest.vbs和jstest.js:

vbtest.vbs:

Set sh = CreateObject("WScript.Shell")
WScript.echo(sh.exec("sqlcmd -S my-server\name -U user -P pass -Q ""exit(USE [schemaName];SELECT COUNT(*) as Count FROM [myView] where [myColumn] = 'mySearchString';)""").StdOut.ReadAll)

jstest.js:

var sh = new ActiveXObject("WScript.Shell");
WScript.Echo(sh.exec("sqlcmd -S my-server\name -U user -P pass -Q \"exit(USE [schemaName];SELECT COUNT(*) as Count FROM [myView] where [myColumn] = 'mySearchString';)\"").StdOut.ReadAll());

当我运行vbtest时,我得到了预期的输出。 当我运行jstest时,sqlcmd的新命令窗口暂停几秒钟,然后我得到一个带有此输出的jscript消息框:

HResult 0x35, Level 16, State 1
Named Pipes Provider: Could not open a connection to SQL Server [53].

1 个答案:

答案 0 :(得分:2)

JScript字符串文字需要转义\

my-server\name

=>

my-server\\name