SQL CLR and embedded resources?

  • I have a dll that contains information for converting ip addresses to a country name, compiled as embedded resources. What I would like is to create a sql function to look up an ip address in the readonly collections and return a country code. I have it all working when I create the assembly with PERMISSION_SET = UNSAFE, but EXTERNAL_ACCESS or SAFE throws the following error

    Msg 6522, Level 16, State 2, Line 1

    A .NET Framework error occurred during execution of user-defined routine or aggregate "GetCountryFromIP":

    System.TypeInitializationException: The type initializer for 'UtherverseShared.IPToCountryProc' threw an exception. ---> System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host.

    The protected resources (only available with full trust) were: All

    The demanded resources were: UI

    System.Security.HostProtectionException:

    at GameWatch.Utils.Net.IPToCountry.LoadFromResources()

    at UtherverseShared.IPToCountryProc..cctor()

    System.TypeInitializationException:

    at UtherverseShared.IPToCountryProc.GetCountry(String ipAddress)

    Is there a way to SAFE'ly (or more likely, with EXTERNAL_ACCESS) access an embedded resource?

  • Hi llloyd

    I think there is no way to work with another trust level than UNSAFE. Embedded resources are unmanaged data so SQL Server doesn't allow them in any other trust level.

  • Ok I can easily enough convert it to just read the files from disk, i thought resources would be better but evidently I hadn't thought that one through. Is there any "best practice" alternative I am overlooking?

  • What about storing your images/file-content within a database table? In this case you wouldn't even need an external access. If you need to access them very often you can use a circular buffer to cache the last n items.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply