MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Mappoint 2004 - SQL 2005 - CLR Integration

This is a discussion on Mappoint 2004 - SQL 2005 - CLR Integration within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; Hello all, I have a problem that I cannot seem to find allot of information for, this site came across ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 12-11-2006
Junior Member
White Belt
 
Join Date: Dec 2006
Posts: 1
Mappoint 2004 - SQL 2005 - CLR Integration

Hello all,
I have a problem that I cannot seem to find allot of information for, this site came across my searches many times so I figured I should start here.
I require the ability to be able to get route info (specifically Distance) from inside a SQL 2005 Function (so that it may be displayed in a view). I know that it may be rough performance wise but I have no other option right now (I don't think anyway...)

I created a small class library in .NET2.0 to load into the SQL Database to handle the calls to the COM+ Mappoint component. I have made much progress but now I cannot seem to get the Item to work.

Am I missing something here with the Assembly security, or can Mappoint even be used in this context?

C# Code:

using System;
using System.Globalization;
using Microsoft.SqlServer.Server;
using MapPoint;
namespace CVSQLMappointAccess
{
public static class CVMapPointUtility
{
[Microsoft.SqlServer.Server.SqlFunction]
public static string CalcDrive(
string calcItem, // Item to calc. TRIPTIME will give you time, Default/UnMatched will give TRIPTIME
string calcUnits, // Units to calc in, kilometers will give you KMS, Default/UnMatched will give MILES
string fromStreet,
string fromCity,
string fromStateProv,
string fromZipPostal,
string fromCountry,
string toStreet,
string toCity,
string toStateProv,
string toZipPostal,
string toCountry)
{
string returnValue = String.Empty;

MapClass map = new MapClass();
FindResults startResults = null;
FindResults finishResults = null;
Location startLoc = null;
Location finishLoc = null;
object index = 1;
string kilometerMatchString = "KILOMETERS";
string tripTimeMatchString = "TRIPTIME";
string kilometerTag = "KM";
string mileTag = "MI";
string unitAppend;

try
{
if (calcUnits.ToUpper() == kilometerMatchString)
{
map.Application.Units = GeoUnits.geoKm;
unitAppend = kilometerTag;
}
else
{
map.Application.Units = GeoUnits.geoMiles;
unitAppend = mileTag;
}
startResults = map.FindAddressResults(fromStreet, fromCity, "", fromStateProv, fromZipPostal, fromCountry);
finishResults = map.FindAddressResults(toStreet, toCity, "", toStateProv, toZipPostal, toCountry);
if (startResults.ResultsQuality == GeoFindResultsQuality.geoAllResultsValid ||
startResults.ResultsQuality == GeoFindResultsQuality.geoFirstResultGood)
{
if (finishResults.ResultsQuality == GeoFindResultsQuality.geoAllResultsValid ||
finishResults.ResultsQuality == GeoFindResultsQuality.geoFirstResultGood)
{
startLoc = (Location)startResults.get_Item(ref index);
finishLoc = (Location)finishResults.get_Item(ref index);
map.ActiveRoute.Waypoints.Add(startLoc, "Start");
map.ActiveRoute.Waypoints.Add(finishLoc, "Finish");
map.ActiveRoute.Calculate();
if (calcItem.ToUpper() == tripTimeMatchString)
{
returnValue = FormatTime(map.ActiveRoute.TripTime);
}
else
{
returnValue = FormatDouble(map.ActiveRoute.Distance, 2) + " " + unitAppend;
}
map.ActiveRoute.Clear();
}
else
{
returnValue = "End Address Not Found";
}
}
else
{
returnValue = "Start Address Not Found";
}
}
catch (Exception)
{
returnValue = "Error With Mappoint Module";
}
finally
{
// Clear ALL mappoint objects
map = null;
startResults = null;
finishResults = null;
startLoc = null;
finishLoc = null;
}
return returnValue;
}
public static string FormatDouble(double val, int decimalPlaces)
{
....
}
public static string FormatTime(double val)
{
....
}
}
}

Registering the DLL with SQL 2005:

ALTER DATABASE MyDB SET trustworthy ON
CREATE ASSEMBLY CVSQLMappointAccess
FROM 'C:\SQLAssemblies\CVSQLMappointAccess.dll'
WITH PERMISSION_SET = UNSAFE;
GO

NOTE: This also automatically adds the Interop.Mappoint.dll into SQL 2005 as unsafe as well.

SQL 2005 Function:

CREATE FUNCTION fn_calc_drive(
@calcItem NVarChar(20),
@calcUnits NVarChar(20),
@fromStreet NVarChar(100),
@fromCity NVarChar(100),
@fromStateProv NVarChar(100),
@fromZipPostal NVarChar(100),
@fromCountry NVarChar(100),
@toStreet NVarChar(100),
@toCity NVarChar(100),
@toStateProv NVarChar(100),
@toZipPostal NVarChar(100),
@toCountry NVarChar(100))
RETURNS NVarChar(100)
AS
EXTERNAL NAME [CVSQLMappointAccess].[CVSQLMappointAccess.CVMapPointUtility].[CalcDrive]
Go

Calling the Function:

Select dbo.fn_calc_drive(
'distance',
'kilometers',
'1027 Wayne Pl',
'Burlington',
'ON',
'CA',
'',
'8 Riverview Ave',
'Mount Pearl',
'NL',
'CA',
'')

Error Received:

Msg 6522, Level 16, State 2, Line 1
A .NET Framework error occurred during execution of user defined routine or aggregate 'CalcDrive':
System.UriFormatException: Invalid URI: The URI is empty.
System.UriFormatException:
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.ComponentModel.Design.RuntimeLicenseContext .GetLocalPath(String fileName)
at System.ComponentModel.Design.RuntimeLicenseContext .GetSavedLicenseKey(Type type, Assembly resourceAssembly)
at System.ComponentModel.LicenseManager.LicenseIntero pHelper.GetCurrentContextInfo(Int32& fDesignTime, IntPtr& bstrKey, RuntimeTypeHandle rth)
at CVSQLMappointAccess.CVMapPointUtility.CalcDrive(St ring calcItem, String calcUnits, String fromStreet, String fromCity, String fromStateProv, String fromZipPostal, String fromCountry, String toStreet, String toCity, String toStateProv, String toZipPostal, String toCountry)

I did a bit of searching regarding Error 6522 and I found mention of permissions issues. I tried to register the Assemblies with EXTERNAL_ACCESS but I get the following error:

Msg 6215, Level 16, State 1, Line 1
CREATE ASSEMBLY failed because method 'get_Application' on type 'MapPoint._Application' in external_access assembly 'Interop.MapPoint' has invalid attribute 0x1003.

Can anybody provide any input on this?

Thanks,
Jody
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 11-27-2007
Junior Member
White Belt
 
Join Date: Nov 2007
Posts: 1
Re: Mappoint 2004 - SQL 2005 - CLR Integration

Hi Jody,

I am currently having the an exact problem, I have registered my dll with unsafe, and when I try to run the CLR, I get

System.UriFormatException: Invalid URI: The URI is empty. ....

I am making a reference to adodb.dll, and when I take out the line of code that instatiated a new instance of adodb.Connection, it works fine.

I would really appreciate if you could tell me how you got around it.

Thanks

Michael


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/mappoint-2004-sql-2005-clr-integration-5466.html

Posted By For Type Date
Author - MP2K Magazine This thread Refback 12-19-2006 09:13 AM
Pushpin Tool Add-in - MP2K Magazine This thread Refback 12-15-2006 05:36 AM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Mappoint and Map Integration gisUser MapPoint 2006/2009 Discussion 0 08-28-2006 12:01 PM
Mappoint 2004 ActiveX Delphi 2005 How to add a Polyline it-fraggel MapPoint 2006/2009 Discussion 3 04-04-2006 01:23 PM
MapPoint 2004 and Visual Studio 2005 Runtime error tizer001 MapPoint 2006/2009 Discussion 10 02-26-2006 09:51 AM
Street detail - Streets/Trips 2005 versus MapPoint 2004 tmtemple MapPoint 2006/2009 Discussion 1 07-01-2005 07:32 AM
MapPoint 2004 updated from Autoroute 2005 Anonymous MapPoint 2006/2009 Discussion 0 03-07-2005 04:49 AM


All times are GMT -5. The time now is 04:12 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map

Cheap Flights to Brussels
Book cheap flights to Brussels online today. Brussels is a city with diverse culture with over 100 museums to visit and an array of different architectural designs to view.

City Break Europe
Take a city break in Europe. Travel Counsellors can help plan and book your European city break.

Thailand Holidays
Thailand Holidays can suit your budget when you book with dealchecker.co.uk. If you are strapped for cash, visit online to find the deal for you.

Holidays to Cancun
The Holiday Place has special offers on holidays to Cancun during the month of September. Book a late summer holiday with us!

Holiday
Searching for the perfect holiday? Well check out ULookUBook online to find out all about your destination and also to book a great value holiday.

Cheap Holiday
For the holiday of your life that is cheap enough to afford with ease, visit Travel.co.uk

Cheap Holidays in Goa
Visit the unique blend of east and west in India! Get information on cheap holidays in Goa, only at On The Beach.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51