ASP 带有存储过程和参数的经典 SQL 服务器 XML 格式

ASP Classic SQL Server XML format with Stored Procedure and Parameters

我正在尝试修改 John 建议的例程,实际上我没有更改任何东西,我只是添加了一个参数,但是我得到了

ADODB.Command error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, 
or are in conflict with one another.

/test/test_xml.asp, line 19 

第 19 行包含:

ocmd.Parameters.Append paramTotals

我也试过其他方式,比如

ocmd.Parameters("@ID").value=1030

但我收到以下错误:

Microsoft OLE DB Provider for SQL Server error '80040e21'   
Procedure or function 'spTEST_XML' expects parameter '@ID', which was not supplied.
/test/test_xml.asp, line 20

第 20 行中有

oCmd.Execute , , 1025

While, if I remove the parameter it works perfectly....

这里是完整例程

Set oXML = Server.CreateObject("MSXML2.DomDocument.6.0")
Set oCmd = Server.CreateObject("ADODB.Command")
oCmd.ActiveConnection = "Provider=sqloledb;server=TEST;Database=test;User ID=sa;Password=test"
oCmd.Properties("Output Stream") = oXML
oXml.async = false
oCmd.CommandText = "spTEST_XML"
ocmd.CommandType=4
Set paramTotals = ocmd.CreateParameter("@ID", adInteger, adParamInput, , 1030)
ocmd.Parameters.Append paramTotals
oCmd.Execute , , 1025
Response.ContentType="text/xml"
Response.Write("<?xml version='1.0' encoding='utf-8'?>")
Response.Write oXML.xml 
Set oXML = Nothing
Set oCmd = Nothing

这里是 StoredProcedure 的顶部

CREATE PROCEDURE [dbo].[spTEST_XML]
(
    @ID     int
)
AS
BEGIN
Declare @SDT datetime = sysdatetime()


if @ID is null 
    begin
        update dbo.PayPal set downloaded=@SDT where Validation='VERIFIED' AND downloaded is null
    end
else
    begin
        update dbo.PayPal set downloaded=@SDT where Validation='VERIFIED' AND ID>=@ID
    end

select
    payment.id reference_id,
    payment.SMSRN SellingManagerSalesRecordNumber,
    cast(dateadd(hh,2,payment.payment_date) as date) payment_date_CET, 
    payment.receiver_email, 
    payment.auction_buyer_id,   
    payment.payer_email, 
    format(payment.mc_gross/XC,'N2') Payment_EUR, 
    format(payment.mc_fee/XC,'N2') Fees_EUR, 
    format((payment.mc_gross-payment.mc_fee)/xc,'N2') Net_EUR,
    format(payment.mc_handling/xc,'N2') Handling_EUR, 
    format(payment.mc_shipping/xc,'N2') Shipping_EUR, 
    payment.payment_status, 
    payment.num_cart_items,
    payment.memo,
    payment.case_id, 
    payment.mc_currency,
    payment.mc_gross,
    payment.mc_fee, 
    payment.mc_handling,
    payment.mc_shipping,
    payment.payment_date
from
(
    select distinct
        p.id,p.payment_date, p.auction_buyer_id, p.mc_currency, p.mc_gross, p.mc_fee, p.payer_email, p.receiver_email, s.sellingmanagersalesrecordnumber SMSRN,
        coalesce(p.mc_handling,0) mc_handling, p.mc_shipping, p.payment_status, 
        p.num_cart_items, p.memo, p.case_id, p.case_type, p.case_creation_date, 
        p.case_closed,
        coalesce(CAST ((Select top (1) rate from dbo.EurRates r where r.Currency=p.mc_currency and r.FXDate<=p.payment_date) as Decimal (10,4)),1) XC
    from dbo.PayPal p
    left join dbo.eBaySales s   on s.referenceID=p.txn_id
    where p.Validation='VERIFIED'
    and p.downloaded=@SDT
) as Payment
order by receiver_email asc, payment_date desc
FOR XML AUTO , ROOT ('PaymentsArray') , ELEMENTS

结束

您的 SP 似乎还可以,无需修改,XML 兼容。

但是,您作为 options 参数传递给 Execute 方法的值 1025 对应于 adCmdText + adExecuteStream 不适合您的命令。

相反,它必须是 adCmdStoredProc + adExecuteStream,等于 1028

因此,以下代码应该适合您。

Set oXML = Server.CreateObject("MSXML2.DomDocument.6.0")
Set oCmd = Server.CreateObject("ADODB.Command")
oCmd.ActiveConnection = "Provider=sqloledb;server=TEST;Database=test;User ID=sa;Password=test"
oCmd.Properties("Output Stream") = oXML
oXml.async = false
oCmd.CommandText = "spTEST_XML"
ocmd.CommandType= 4
Set paramTotals = ocmd.CreateParameter("@ID", adInteger, adParamInput, , 0)
ocmd.Parameters.Append paramTotals
oCmd.Execute , , 4 + 1024 ' adCmdStoredProc + adExecuteStream
Response.ContentType="text/xml"
Response.Write("<?xml version='1.0' encoding='utf-8'?>")
Response.Write oXML.xml 
Set oXML = Nothing
Set oCmd = Nothing