Community of VE/MapPoint Users and Developers
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 ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| Mappoint 2004 - SQL 2005 - CLR Integration 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 |
| |||
| 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 |
![]() |
| ||||
| 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 | |
| |
| ||||
| 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 |
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.