ELMAH存储过程中的XQuery

时间:2015-05-05 19:51:04

标签: sql-server xquery elmah xquery-sql

我在ELMAH_Error表中添加了列,并编辑了ELMAH_LogError存储过程来设置和插入值。使用xquery从xml列中提取新列值。使用xquery时插入失败。它可以设置静态值,如果我手动执行存储过程也可以。知道为什么我使用xquery时失败了吗?

USE [ELMAH]
GO
/****** Object:  StoredProcedure [dbo].[ELMAH_LogError]    Script Date: 05/04/2015 16:06:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[ELMAH_LogError]
(
    @ErrorId UNIQUEIDENTIFIER,
    @Application NVARCHAR(60),
    @Host NVARCHAR(30),
    @Type NVARCHAR(100),
    @Source NVARCHAR(60),
    @Message NVARCHAR(500),
    @User NVARCHAR(50),
    @AllXml XML,
    @StatusCode INT,
    @TimeUtc DATETIME
)
AS
  Set NOCount ON

    Declare @QueryString varchar(1000)
    Declare @Method varchar(10)
    Declare @URL varchar(100)
    Declare @HTTP varchar(100)

    --Insert fails if I set these values with xquery

    SET @QueryString = @AllXml.value('(/error/serverVariables/item[@name="QUERY_STRING"]/value/@string)[1]','varchar(1000)')
    SET @Method = @AllXml.value('(/error/serverVariables/item[@name="REQUEST_METHOD"]/value/@string)[1]','varchar(10)')
    SET @URL = @AllXml.value('(/error/serverVariables/item[@name="URL"]/value/@string)[1]','varchar(100)')
    SET @HTTP = @AllXml.value('(/error/serverVariables/item[@name="HTTP_REFERER"]/value/@string)[1]','varchar(100)')


    INSERT
    INTO
        [ELMAH_Error]
        (
            [ErrorId],
            [Application],
            [Host],
            [Type],
            [Source],
            [Message],
            [User],
            [AllXml],
            [StatusCode],
            [TimeUtc],
            [QueryString],
            [Method],
            [URL],
            [HTTP]
        )
    VALUES
        (
            @ErrorId,
            @Application,
            @Host,
            @Type,
            @Source,
            @Message,
            @User,
            @AllXml,
            @StatusCode,
            GETDATE(),
            @QueryString,
            @Method,
            @URL,
            @HTTP
        )

0 个答案:

没有答案