Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xml Parsing Issue in sql job

I am getting an error while executing the query in a SQL Server job. But if I execute it directly, it works fine.

Executed as user: NT AUTHORITY\SYSTEM.

XML parsing: line 10, character 33
Unexpected end of input [SQLSTATE 42000] (Error 9400). The step failed.
SQL Severity 16, SQL Message ID 9400

Code:

    declare  @URL VARCHAR(max) 

    set @url = 'http://www.spa.gov.sa/english/rss.xml'

    declare  @xmlT TABLE (yourXML XML)
    DECLARE @Response nvarchar(max)
    DECLARE @XML xml
    DECLARE @Obj int 
    DECLARE @Result int 
    DECLARE @HTTPStatus int 
    DECLARE @ErrorMsg nvarchar(MAX)

    EXEC @Result = sp_OACreate 'MSXML2.XMLHttp', @Obj OUT 

    EXEC @Result = sp_OAMethod @Obj, 'open', NULL, 'GET', @URL, false
    EXEC @Result = sp_OAMethod @Obj, 'setRequestHeader', NULL, 'Content-Type', 'application/x-www-form-urlencoded'
    EXEC @Result = sp_OAMethod @Obj, send, NULL, ''
    EXEC @Result = sp_OAGetProperty @Obj, 'status', @HTTPStatus OUT 

    INSERT @xmlT ( yourXML )
    EXEC @Result = sp_OAGetProperty @Obj, 'responseXML.xml'--, @Response OUT 


    INSERT into Tlb(discp, tit, datee, linkk)

--below statement creates problem when i remove this statement it works fine everywhere

        SELECT   
            N.C.value('description[1]', 'nvarchar(max)') discp,   
            N.C.value('title[1]', 'varchar(999)') tit,
            N.C.value('pubDate[1]', 'varchar(99)') datee,
            N.C.value('link[1]', 'varchar(999)') linkk
        FROM
            @xmlT 
        CROSS APPLY 
            yourXML.nodes('//channel/item') N(C)
like image 405
user2659502 Avatar asked Jan 28 '16 06:01

user2659502


1 Answers

Do you know about the Sql Agent TEXTSIZE?

Specify directly in the procedure TEXTSIZE 512 and exec, you'll get the same error in this case

SET TEXTSIZE -1

OR other value, i use -1 for unlimited size by default sql server textsize on the SQL Agent is 512

like image 200
Leandro Santos Avatar answered Oct 31 '22 10:10

Leandro Santos