Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 797
  • Last Modified:

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

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
COANetwork
Asked:
COANetwork
  • 2
1 Solution
 
virtuadeptCommented:
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
 
COANetworkAuthor Commented:
Can it be done with a CLR function?
0
 
virtuadeptCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now