-- Register the unrestricted access privileged assembly
-- Create assembly with external access
create assembly searchEA
from 'c:\types\searchEA.dll'
with permission_set = external_access
go

-- Create assembly without external access
create assembly searchSafe
from 'c:\types\searchsafe.dll'
with permission_set = safe
go

-- Create function on assembly with external access
create function WebSearchEA(@sym nvarchar(10))
returns real
external name searchEA.SearchEngine.WebSearch
go

-- Create function on assembly with no external access
create function WebSearchSafe(@sym nvarchar(10))
returns real
external name searchSafe.SearchEngine.WebSearch
go

-- now, attempt to use them
declare @a REAL
-- this will work properly
SET @a = dbo.WebSearchEA('SQL+Server+2005')
PRINT @a
-- this fails with a code access security violation
SET @a = dbo.WebSearchSafe('SQL+Server+2005')
PRINT @a