Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-02-06
3
Medium Priority
?
794 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 2000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

664 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