Community of VE/MapPoint Users and Developers
This is a discussion on Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (1/6) within the Virtual Earth Blogs forums, part of the Blogs category; Integrating SQL Server 2008 and Virtual Earth So far we have given an overview about some of the important features ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (1/6) Integrating SQL Server 2008 and Virtual EarthSo far we have given an overview about some of the important features in both SQL Server 2008 and Virtual Earth. Now we will bring the software and the service together. We just learned that we have basically 3 options to add data from SQL Server 2008 to Virtual Earth:
We will have a look at all of these options but we will also have a look at how we can draw on Virtual Earth maps and insert the resulting VEShape-objects as geography data into SQL Server 2008. Geocoding in SQL Server 2008Wait a minute: geocoding in SQL Server 2008? Is that possible? Geocoding is not a feature of SQL Server 2008 but it is a feature of Virtual Earth so maybe we can bring the software and the service together in a way that they complement each other even more. The Virtual Earth Platform spans actually over 2 groups of services. The MapPoint Web Service and Virtual Earth itself. As an enterprise customer, you have always access to both services but everybody can sign-up to a free developer account for the MapPoint Web Service as well. The key is that since SQL Server 2005 we have a Common Language Runtime (CLR) in the database. The CLR allows us to write .NET managed code for procedures or triggers and that allow us to make a calls to the MapPoint Web Service. Let’s assume we have a table to record occurrences of “Foot and Mouth Disease”. The table is defined as follows: CREATE TABLE [FMD]( Usually people will insert the date, city and county as well as the number of diseased cattle, pigs and sheep. They wouldn’t want to bother to geocode the data. On the other side it will help us a lot if we can have the geocodes and use them for some geographic analysis within SQL Server 2008 Thus the plan is to intercept the INSERT-statement with an INSTEAD OF trigger. We use the address information in the original statement as parameters in a SOAP-call to the MapPoint Web Service which returns us a latitude and longitude. With this information we can create a geography object of type point for SQL Server 2008 and then we execute an INSERT statement which adds these values to the original statement. Before we start to develop our CLR trigger we first need to change a setting in the database to allow .NET managed code to access external data: ALTER DATABASE VESQLWP SET TRUSTWORTHY ON Now we can start coding. We start up the Visual Studio 2005 or higher and create a new database project. In the database project we create a new CLR trigger and we will name the class “Geocode”. In the project properties we make sure that the assembly will have external access: Now we add a web reference to the MapPoint Web Service and we name it MWS (https://mappoint-css.live.com/MwsSignup/Eval.aspx). Please note: If you haven’t done so yet sign up for a free developer account since you will need the credentials in a few minutes. OK, we’re ready to go. You will find the complete code ready for download here
Please note: You will have to enter your Virtual Earth Platform User ID and Password in the file Geocode.vb) Basically here is what happens: ... Now we compile the project and load the assembly into the database: CREATE ASSEMBLY Geocode Next we have to provide another assembly for XML Serialization. Why do we need to do this? Calling web service methods requires serializing all the types being used in xml. Outside SQL Server this serialization code is generated at runtime, compiled and loaded in the application. However, for security and reliability reasons, SQL Server does not allow you to dynamically load assemblies. The Visual Studio automatically recognized that we need this assembly and it compiled it in the project’s bin folder. However, SQL Server 2005 did not allow the automated provisioning, we have to load this assembly as follows: CREATE ASSEMBLY [Geocode.XmlSerializers] And Finally we create the trigger on the database table CREATE TRIGGER trig_Geocode Let's insert a few records and check the results. Note: to easily review the geometry or geography data types use the method, STAsText(). (to be continued) Technorati Tags: Virtual Earth,SQL Server 2008 ![]() ![]() Click here to view the article. Last edited by Eric Frost; 03-03-2008 at 08:20 AM. |
![]() |
| ||||
| Posted By | For | Type | Date | |
| Integrating SQL Server 2008 and Virtual Earth {Forum} - Launchwave | This thread | Refback | 03-04-2008 02:55 PM | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (3/6) | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-02-2008 03:52 PM |
| Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (2/6) | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-02-2008 03:52 PM |
| Virtual Earth & SQL Server 2008 - Part 2: Spatial Data Management in SQL Server 2008 (3/3) | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-02-2008 01:40 PM |
| Virtual Earth & SQL Server 2008 - Part 2: Spatial Data Management in SQL Server 2008 (2/3) | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-02-2008 01:40 PM |
| Virtual Earth & SQL Server 2008 - Part 2: Spatial Data Management in SQL Server 2008 (1/3) | Johannes Kebeck's Blog | Virtual Earth Blogs | 0 | 03-02-2008 01:40 PM |
Flight Departures
Check Holiday Hypermarket to find flight departures to numerous exotic destinations. We link to details on flight departures and arrivals to help you find information fast.
City Break Holidays
Book city break holidays through Travel Counsellors. A personal travel advisor will help with your city break holiday plans.
Holidays Thailand
Holidays in Thailand are hugely diverse with wonderful luxury resorts and beaches but also some lovely forested mountains with interesting hill tribes. See dealchecker.co.uk.
Cancun Holidays
Cancun holidays offer beautiful scenery, calm waters and plenty of shopping. Get a taste of the good life while on holiday in Cancun.
Cheap Balearics Holidays
Cheap Balearics holidays are available if you know when to book and who to book with. The Balearics have many fascinating places to visit all year round. The partying never stops.
Cheap Travel
For cheap travel options, visit Travel.co.uk and explore the benefits of our comparison site.
Lanzarote Holidays
Visit the easternmost island of the archipelago! Book Lanzarote holidays at On The Beach!