How do I use a SP in SQL Server 2014 to call a external XML source? -


i attempting retrieve currency exchange rates http://www.floatrates.com/daily/usd.xml using sp in sql server 2014. result in xml. created following sproc:

--drop procedure [dbo].[proc_callwebservice] create procedure [dbo].[proc_callwebservice]     declare @obj int     declare @surl varchar(200)     declare @response varchar(max)      set @surl = 'http://www.floatrates.com/daily/usd.xml'      exec sys.sp_oacreate 'msxml2.serverxmlhttp', @obj out     exec sys.sp_oamethod @obj, 'open', null, 'get', @surl, false     exec sys.sp_oamethod @obj, 'send'     exec sys.sp_oagetproperty @obj, 'responsetext', @response out      select @response [response]     exec sys.sp_oadestroy @obj return 

and when run sproc null in return instead of xml.

what need change in proc xml response site mentioned above?

ok tested following sp pulls xml data:

drop procedure [dbo].[proc_callwebservice] go create procedure [dbo].[proc_callwebservice]     if object_id('tempdb..#xml') not null drop table #xml     create table #xml ( data xml )      declare @obj int     declare @surl varchar(200)     declare @response varchar(max)      set @surl = 'http://www.floatrates.com/daily/usd.xml'      declare @xml xml     declare @result int      declare @httpstatus int      declare @errormsg varchar(max)      exec @result = sp_oacreate 'msxml2.xmlhttp', @obj out      exec @result = sp_oamethod @obj, 'open', null, 'get', @surl, false     exec @result = sp_oamethod @obj, 'setrequestheader', null, 'content-type', 'text/html'     exec @result = sp_oamethod @obj, send, null, ''     exec @result = sp_oagetproperty @obj, 'status', @httpstatus out      --exec @result = sp_oagetproperty @obj, 'responsexml.xml', --@response out       insert #xml ( data )    exec @result = sp_oagetproperty @obj, 'responsexml.xml'--, @response out      select * #xml return   

the way got around it, use #xml hash temp table retrieve response, , select response it.

this because of way mime types , downloading of file contents completed, bringing binary value, no response header, , because wasnt completeting full action of doing conversion xml

-- needs below, im keeping part of comment

when try , run sp following error: return me response of null.

msg 15281, level 16, state 1, procedure sp_oacreate, line 1 sql server blocked access procedure 'sys.sp_oacreate' of component 'ole automation procedures' because component turned off part of security configuration server. system administrator can enable use of 'ole automation procedures' using sp_configure. more information enabling 'ole automation procedures', search 'ole automation procedures' in sql server books online. 

to fix issue,

right click on server instance -> click facets select "server configuration" under facets , in facet properties change oleautomationenabled = true

or if doesnt work use in query window inside sql server management tools.

sp_configure 'show advanced options', 1; go reconfigure; go sp_configure 'ole automation procedures', 1; go reconfigure; go 

the documentation above statement here: https://msdn.microsoft.com/en-us/library/ms191188.aspx


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -