在实现存储过程扩展的过程中遇到了一个比较麻烦的问题:我希望通过编写一个动态链接库和一个WebService,实现一些涉及数据库的操作,具体的思路如下, 
(1)创建一个CLR存储过程,存储过程调用DLL 
(2)Dll调用WebServiceDLL中实际就是通过GET方法向WebService传递一个URL地址,WebService通过URL中不同的参数执行不同的操作。现在的问题是,编写的DLL和WebService联调后通过,但在存储过程中调用DLL时出现异常。DLL的主函数如下
[Microsoft.SqlServer.Server.SqlFunction]
public static void Get_Http(string tUrl)
{
     string str = string.Empty;
     string url = tUrl;
     HttpWebRequest request;
     HttpWebResponse response;
     try
     {
          //此处就开始有问题了
          request = (HttpWebRequest)System.Net.HttpWebRequest.Create(url);
          request.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows server 2003)";
          response = (HttpWebResponse)request.GetResponse();
          System.IO.Stream stream = response.GetResponseStream();
          Encoding source;
          source = Encoding.UTF8;
          StreamReader sr = new StreamReader(stream, source);
          str = sr.ReadToEnd();
          sr.Close();
          stream.Close();
          SqlContext.Pipe.Send("0");
      }
      catch(Exception msg)
      {
          SqlContext.Pipe.Send(msg.Message);
      }
}
---------------------
request = (HttpWebRequest)System.Net.HttpWebRequest.Create(url); 这一句有问题,从存储过程中看显示的错误信息为:Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.求教。有没有问和我遇到一样的问题。多谢。

解决方案 »

  1.   

    正常情况下:request = (HttpWebRequest)System.Net.HttpWebRequest.Create(url);
    这个可以获取到页面内容么?
    没看到你的存储过程怎么调用的DLL,要给web地址参数吧?可以贴出来给大家看看。
      

  2.   

    我在Web页面上引用了我写的DLL,然后通过它调用WS,无任何异常。 感觉好像是权限的问题。我的动态链接库实际上就是获取一个HTTP页面,只不过这个页面现在是一个WebService而已。所以我没有给出WS的具体内容(因为WS的内容是什么并不需要关心),现在是在Create这一步就错了。
      

  3.   

    SQL还有这个功能?搬个凳子过来^^^^
      

  4.   

    http://community.csdn.net/Expert/topic/5611/5611477.xml?temp=.2812158