我写了个dll,很简单就是实现ping这个操作,代码没有问题,我调用这个函数的时候,总是出错
Msg 6522, Level 16, State 2, Line 1
A .NET Framework error occurred during execution of user defined routine or aggregate 'getip': 
System.Net.NetworkInformation.PingException: An exception occurred during a Ping request. ---> System.Security.SecurityException: Request for the permission of type 'System.Net.DnsPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
System.Security.SecurityException: 
   at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
   at System.Security.CodeAccessPermission.Demand()
   at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
   at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
System.Net.NetworkInformation.PingException: 
   at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
   at UserDefinedFunctions.get_ip(String ym)
.
我该如何才能解决呢???请知道的朋友帮个忙

解决方案 »

  1.   

    解决了,首先生成一个强名sn.exe -k
    然后,编译这个dll的时候,引用这个强名\
    然后,
    EXEC('CREATE ASYMMETRIC KEY ping_Key FROM EXECUTABLE FILE = ''' +  'C:\Documents and Settings\tal13\My Documents\Visual Studio 2005\Projects\ClassLibrary1\ClassLibrary1\bin\Release\ping.dll'';');
    CREATE LOGIN myping_Login FROM ASYMMETRIC KEY ping_Key
    GRANT EXTERNAL ACCESS ASSEMBLY TO myping_LoginCREATE ASSEMBLY [ping] FROM  'C:\Documents and Settings\tal13\My Documents\Visual Studio 2005\Projects\ClassLibrary1\ClassLibrary1\bin\Release\ping.dll'
    WITH permission_set=External_Access;
    GOCREATE FUNCTION get_ip (@YM nvarchar(256))
    RETURNS nvarchar(256)
    AS EXTERNAL NAME [ping].[UserDefinedFunctions].[get_ip];
    GO====CSDN 小助手 V2.5 2005年11月05日发布====
    CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
    界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
    下载:http://szlawbook.com/csdnv2