Solved

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

Posted on 2013-02-06
3
774 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
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
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.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

910 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

21 Experts available now in Live!

Get 1:1 Help Now