Solved

Get XML data from web page (via HTTP) into SQL Server 2008

Posted on 2013-02-06
3
782 Views
Last Modified: 2013-02-06
I have an HTTP URL that accepts a single parameter and returns an XML document.  This is not a web service, and I do not control the source - it's third-party.  I need to be able to access that URL (providing the value for the input parameter) from SQL Server and receive the resulting XML for the purpose of updating a table with the data.  What is the best way to do this?
The URL is a geocoding service, here is an example:
http://geocode-maps.yandex.ru/1.x/?geocode=%D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0,+%D1%83%D0%BB+%D0%B3%D1%80%D1%83%D0%B7%D0%B8%D0%BD%D1%81%D0%BA%D0%B0%D1%8F+%D0%BC
0
Comment
Question by:COANetwork
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Expert Comment

by:virtuadept
ID: 38860091
If I were going to do this I would write a .NET program that would read the URL and parse out the XML and then call SQL Server procedure passing in the XML. MS SQL doesn't have a build in way to do http requests. And if it did, it would be a huge security risk.
0
 
LVL 9

Author Comment

by:COANetwork
ID: 38860192
Can it be done with a CLR function?
0
 
LVL 8

Accepted Solution

by:
virtuadept earned 500 total points
ID: 38860361
Yes I believe that is another good way to go. I did a little searching and didn't find any CLR functions already written for this, but it can't be that hard to do. I would make sure that the CLR does some sanity checks on the returned XML before putting it back to the database, just to make sure this can not become a vector for a SQL Injection attack.

If you haven't done a CLR before (and I've only done one :) ) then here is a good starting point for that.

http://msdn.microsoft.com/en-us/library/ms131052(v=sql.105).aspx

And you would just need to take that sample code and then add in some references for the system.net namespace.

http://msdn.microsoft.com/en-us/library/gg145039.aspx

And you need to enable the CLR on the database before you can get started. ALso when I was writing my (one) CLR I had to put it in unsafe mode because I was referencing a DLL that wasn't signed or something. Can't remember exactly. Depending on what .NET namespaces you reference you may have some issues with that also.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
GeoClustering  and AOG 25 43
Table where row act as column 11 69
Rebooting Witness SQL Server 2 25
How come this XML node is not read? 3 28
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question