I have created a simple, 1 method DLL to convert a string address to a Lat/Lon string using an in-house web service. The code is simply this:
public class GeoCodeLib
{
[SqlFunction(IsDeterministic=false)]
public SqlString GetLatLon(SqlString addr)
{
Geo.GeoCode gc = new Geo.GeoCode();
Geo.Location loc = gc.GetLocation(addr.Value);
return new SqlString(string.Format("{0:N6}, {1:N6}", loc.LatLon.Latitude, loc.LatLon.Longitude));
}
}
I have targeted .NET Framework 2.0. We're using SQL Server 2008 R2. The assembly has been added to the database (the assembly is called GeoCodeSqlLib.dll). We've set no permissions on it.
I can't seem to call it. I've tried:
select GeoCodeSqlLib.GeoCodeLib.GetLatLon('12143 Thompson Dr. Fayetteville, AR 72704')
That gives me the message, Cannot find either column "GeoCodeSqlLib" or the user-defined function or aggregate "GeoCodeSqlLib.GeoCodeLib.GetLatLon", or the name is ambiguous.
I've tried:
CREATE FUNCTION GetLatLon(@amount varchar(max)) RETURNS varchar(max)
AS EXTERNAL NAME GeoCodeSqlLib.GeoCodeLib.GetLatLon
That gives me the message, Could not find Type 'GeoCodeLib' in assembly 'GeoCodeSqlLib'.
I'm clearly missing something. The documentation's samples are all really basic and whatever step I'm missing, I just haven't been able to find it in the documentation.
Update
Thanks for all the help. So a few things:
- I need to make it external access to get be able to make a web service call.. I didn't realize I needed to create a SQL Server project. I was just doing a regular C# class library.
- So I created the SQL Server project. The SQL Server project doesn't support web service references. I tried adding a reference to my original DLL, so the new SQL Server project DLL acts as a proxy to the original DLL (the code in my original question).
- This, however, gives me:
Assembly 'geocodesqllib, version ...' was not found in the SQL catalog.But I can't add it to the catalog because it needs External Access, which I can't do from a non SQL Server project (that I know of).
They really don't want to make this easy, do they?
Update 2
As per my comments below, the final issue appears to be the config file. It isn't finding the setting. The name of the server has been changed to protect the innocent:
<applicationSettings>
<GeoCodeSqlLib.Properties.Settings>
<setting name="GeoCodeSqlLib_ourserver_GeoCode" serializeAs="String">
<value>http://ourserver/GeoCode.svc</value>
</setting>
</GeoCodeSqlLib.Properties.Settings>
</applicationSettings>
The error I get is:
System.Configuration.SettingsPropertyNotFoundException: The settings property 'GeoCodeSqlLib_ourserver_GeoCode' was not found.
static.