Click to See Complete Forum and Search --> : ADO and ForXml


PavelShvarts
October 20th, 2004, 09:22 AM
Below functon work fine in VB project but did not work neither in ASP or wscript. The error is "Syntax error or access violation" in line cmd.Execute , , adExecuteStream
Any idea why?
Thanks for looking


Function GetXmlBySP(sp, cnnStr)
Const adUseClient = 3
Const adTypeText = 2
Const adCRLF = -1
Const adModeRead = 1
Const adCmdStoredProc = 4
Const adExecuteStream = 1024

GetXmlBySP = ""

Set cnn = CreateObject("ADODB.Connection")
cnn.Open cnnStr

Set cnn = CreateObject("ADODB.Connection")
cnn.CursorLocation = adUseClient
cnn.Open cnnStr

Set ostr = CreateObject("ADODB.Stream")
ostr.Type = adTypeText
ostr.LineSeparator = adCRLF
ostr.Mode = adModeRead
ostr.Open

Set cmd = CreateObject("ADODB.Command")
Set cmd.ActiveConnection = cnn
cmd.Properties("Output Stream").Value = ostr
cmd.CommandType = adCmdStoredProc
cmd.CommandText = sp

cmd.Execute , , adExecuteStream 'ERROR in ASP and W(S)Script, work in VB

Set cmd.ActiveConnection = Nothing
cnn.Close
If Err.Number <> 0 Then Exit Function

ostr.Position = 0
Const ReadBytes = 2048
strXMLOutput = ""
Do While Not ostr.EOS
strXMLOutput = strXMLOutput & ostr.ReadText(ReadBytes)
Loop
GetXmlBySP = strXMLOutput
End Function