When I execute a Stored Procedure through a SQL Agent Job, I get the following error message:
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
However, when I run it manually, it is successful.
This is the procedure which I am executing:
decalre @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)
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)