Solved

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

Posted on 2013-02-06
3
770 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
  • 2
3 Comments
 
LVL 8

Expert Comment

by:virtuadept
Comment Utility
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
Comment Utility
Can it be done with a CLR function?
0
 
LVL 8

Accepted Solution

by:
virtuadept earned 500 total points
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to query date ranges with SQL 6 21
What .NET website keeps me current? 9 28
Sql query 34 14
SQL Transaction logs 8 4
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now