问题
I found this error looking for a solution to a problem of retrieving XML at ASP classic: Declaring XML output parameters with ADODB in ASP Classic
I have the same error working with Classic ASP and SQL Server 2003. I used to work with a .dll in VB6, where I could get the XML code. But now I need to do it from SQL direct to ASP. Did you manage to solve it?
My code in classic ASP so far is:
set objCommandoOP = Server.CreateObject("ADODB.Command")
Set objCommandoOP.ActiveConnection = objConexion
objCommandoOP.CommandType = adcmdStoredProc
objCommandoOP.CommandText="spProducesXML"
set ParamEnt = objCommandoOP.CreateParameter("@CodOne", adInteger, adParamInput, 4, Entidad())
objCommandoOP.Parameters.Append ParamEnt
set ParamUser = objCommandoOP.CreateParameter("@CodTwo", adInteger, adParamInput, 4, Usuario())
objCommandoOP.Parameters.Append ParamUser
set ParamFrac = objCommandoOP.CreateParameter("@GroupType", adInteger, adParamInput, 4, Request("GrupoFrac"))
objCommandoOP.Parameters.Append ParamFrac
set ParamReturn = objCommandoOP.CreateParameter("@paramReturn", adXML, adParamInputOutput, 4, 0)
objCommandoOP.Parameters.Append ParamReturn
set objResultseto = Server.CreateObject("ADODB.RecordSet")
'Internal procedure that execute the ddbb sp
ExecProcedure objResultseto, adOpenStatic, objCommandoOP
sResult = "<dmo:OperationImport xmlns:dmo='http://www.example.es/XML' xmlns:xs='http://www.w3.org/2001/XMLSchema' />"
sResult = sResult & ParamReturn
sResultXML= sResultXML & "</dmo:OperationImport>"
The error happens at the "adXML" line, since as David I cannot find a XML variable to bring the parameter from the ddbb. I try to take it as paramReturn of the SQL procedure (with FOR XML EXPLICIT), any other ideas?
回答1:
The reason you receive an error on the adXML
line is because there is no DataTypeEnum
for this data type.
In ADO 2.6 the ADODB.Command
object was extended to support passing and receiving XML data using the ADODB.Stream
object.
To pass an XML data type in the ADODB.Command
use the CommandStream
property
Set stream = Server.CreateObject("ADODB.Stream")
Call stream.Open()
Call stream.WriteText(xml, adWriteChar)
'Set ADODB.Stream to CommandStream before executing ADODB.Command
command.CommandStream = stream
command.Execute(, , adExecuteStream)
To retrieve an XML data type use the dynamic property Output Stream
Set stream = Server.CreateObject("ADODB.Stream")
Call stream.Open()
'Set ADODB.Stream to dynamic property "Output Stream"
command.Properties("Output Stream") = stream
command.Execute(, , adExecuteStream)
'Reset stream position before reading
stream.Position = 0
xml = stream.ReadText
Useful links
- Capturing XML output from ADO using a Stream object
回答2:
I finally could make with a workaround. basically sending the parameter from SQL as a varchar(max)
and not as XML, then treating it in ASP as a Object Resulset were I convert the varchar to an XML. Tried up with files of more than 30k characters and still works.
Classic ASP code so far:
`
dim objResultseto
set objResultseto = Server.CreateObject("ADODB.RecordSet")
AbrirProcAlmacenado objResultseto, adOpenStatic, objCommand
if objResultseto.EOF= false then
while (objResultseto.EOF = false)
Set xmlOperaciones = Server.CreateObject("Msxml2.DOMDocument.4.0")
xmlOperaciones.Async = False
xmlOperaciones.loadXML(objResultseto("XML_VAR"))
xmlOperaciones.setProperty "SelectionNamespaces","xmlns:dmo='http://www.webpage.com/'"
if xmlOperaciones.parseError = 0 then
xmlOperaciones.Save("C:\Example.xml")
sResultado= "OK"
end if
objResultseto.movenext
wend
else
response.Write("There are no these kind of operations")
response.end
end if
´
Remember that this is just a workaround.
Cheers!
来源:https://stackoverflow.com/questions/23867480/xml-output-parameters-with-adodb-in-asp-classic