Register  |  Login   Search
ThinkGeo - GPS Tracking and Mapping Solutions  |  Home  |  Cygnus Track  |  Developer Community
 
LivePerson Chat

Discussion Forums

The online community for users of Map Suite GIS components

RSS Feed Available AddThis - Bookmarking and Sharing Button Printer Friendly

PrevPrev NextNext

Implementing Geocode USA Into a SQL Stored Procedure

Posted by ThinkGeo on 11-05-2008 05:40 PM

This article will show you how to implement Geocode USA within a managed stored procedure in SQL Server 2005. The simple procedure involves preparing your files, configuring your database environment, creating an assembly and then building your stored procedure from that assembly.

Download Tutorial Materials
Download Demo Application

Steps

1. Prepare Files

Unzip the GeocodeSample.zip file to C:\GeocodeSample. Please note that the included GeocodeUSA.dll is from the free evaluation edition of Geocode USA; if you are a licensed user of the full version, you will want to use your own copy of GeocodeUSA.dll instead.

Contents of the GeocodeSample.zip file

2. Configure Database Environment

Open the SQL Server 2005 Surface Area Configuration tool and select the Surface Area Configuration for Features.

The SQL Server 2005 Surface Area Configuration tool

Enable the CLR Integration so that you can CREATE ASSEMBLY.

How to enable CLR integration

Open SQL Server Management Studio and create a new database. In this example we used: GeocodeSample. (The Database Owner must be a SQL server account, not a domain account.)

Creating a new database

Once the database has been created, use the following SQL command to alter the database and set TRUSTWORTHY to ON, so that you can use UNSAFE PERMISSION SET.

ALTER DATABASE GeocodeSample SET TRUSTWORTHY ON

Create a new assembly and choose the SQLGeocodeUSA.dll from the Path to Assembly file browser. Be sure to set the Permission Set as Unsafe. Click OK. Now you will see two assemblies: GeoCodeUSA and SQLGeocodeUSA. Double-check that the Permission Set is set to Unsafe.

Creating a new assembly and setting the Permission Set to Unsafe

Now you can create a stored procedure from the assembly. For example:

CREATE PROCEDURE ReverseGeocode
    -- Set default value, idx files directory
    @GeocodeIdxFolder nvarchar(200)='C:\GeocodeIdx2006fe',
    @Longitude float = 0.0,
    @Latitude float = 0.0
AS
    EXTERNAL NAME
        SQLGeocodeUSA.SQLGeocodeUSAEngine.ReverseGeoCode

Then, you can use this procedure as common stored procedure:

EXECUTE [GeocodeSample].[dbo].[ReverseGeoCode];
     @Longitude = -95.2808458305725,
     @Latitude = 38.9553176794061

Which gives you these results:

Results of the above SQL query

3. Instantly Configuring the Database Environment

First, start SQL Server Management Studio. Open the GeocodeSample.sql file, then execute the SQL statement.

Executing the GeocodeSample.sql statement

4. Client Demonstration

Demonstration code is also provided. The SQLGeocodeUSA project is a class library project, which acts as a bridge between the Geocode USA core and SQL Server 2005. You can use the SQLGeocodeClientDemo to demonstrate how to call the stored procedure in client code.

The GeocodeSample demo application

0 Comments

Active Forums 4.1