2014-12-16 10 views
0

를 통해 VBScript를 :SQLCMD는 JScript의 중단하지만 나는 두 개의 스크립트, vbtest.vbs 및 jstest.js이 WSH

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를 실행할 때 예상되는 결과를 얻습니다.

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

답변

2

의 JScript 문자열 리터럴은 \ 위해 탈출 필요 : 나는 jstest를 실행하면 SQLCMD에 대한 새로운 명령 창은 몇 초 동안 그것에 아무것도 중단 , 그럼 나는이 출력으로 JScript를 메시지 상자를 얻을

my-server\name 

=>

my-server\\name 
+0

감사합니다, 나는 내가 놓친 믿을 수 없어 .... 그, 특히 내가 "이스케이프 고려. – Corey