Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 SQLFunction throws a security exception

Author  Topic 

mathmax
Yak Posting Veteran

95 Posts

Posted - 2008-07-18 : 12:36:20
Hello,

I've created a SQL Server project on Visual Studio in order to make a function usable by SQL Server.
In this method, I invoke an external function from an OLE dll:


[SqlFunction]

public static SqlString Transform(object exp, string cSayPicture)
{

Type _OLEType = Type.GetTypeFromProgID("sampleoleserver");

Object _OLEServer = Activator.CreateInstance(_OLEType);

var result = InvokeParameters("MyTransform", new object[] { 2, "@C" });
....
}


The method has been successfully deployed by Visual Studio, but when I try to use this function in a query, I get the following security error message:

Msg 6522, Level 16, State 2, Line 1
A .NET Framework error occurred during execution of user defined routine or aggregate 'Transform':
System.TypeInitializationException: The type initializer for 'UserDefinedFunctions' threw an exception. ---> System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
System.Security.SecurityException:
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Assembly asm, SecurityAction action)
at UserDefinedFunctions..cctor()
System.TypeInitializationException:
at UserDefinedFunctions.Transform(Object exp, String cSayPicture)

What should I do to allow the execution of my method ?

Regards,

mathmax
   

- Advertisement -