首页 新闻 会员 周边 捐助

SQL2005 System.Security.Permissions.FileIOPermissi

0
悬赏园豆:20 [已解决问题] 解决于 2009-04-01 22:50

在vs2005下编写的存储过程代码如下:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Xml;
public partial class StoredProcedures
{
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void StoredProcedure1()
    {
        SqlConnection cnn = new SqlConnection("context connection=true");
        cnn.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = cnn;
        cmd.CommandText = "select * from UserTest for xml raw('pesron')";
        XmlReader xr = cmd.ExecuteXmlReader();
        DataSet ds = new DataSet();
        ds.ReadXml(xr);
        ds.WriteXml("d://wu.xml");
    }
};

在sql2005下执行该存储过程时,出现以下错误:
消息 6522,级别 16,状态 1,过程 StoredProcedure1,第 0 行
在执行用户定义例程或聚合 'StoredProcedure1' 期间出现 .NET Framework 错误:
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, 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.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
  at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
  at System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding)
  at System.Data.DataSet.WriteXml(String fileName, XmlWriteMode mode)
  at System.Data.DataSet.WriteXml(String fileName)
  at StoredProcedures.StoredProcedure1()

谢谢!

吴晨晖的主页 吴晨晖 | 初学一级 | 园豆:180
提问于:2009-04-01 00:20
< >
分享
最佳答案
0

把 d: 盘指定为 Every One 完全控制 

再试这个

ALTER ASSEMBLY <you_assembly_name> WITH PERMISSION_SET=EXTERNAL_ACCESS

参见 http://social.msdn.microsoft.com/Forums/en-US/sqlnetfx/thread/15ae5ce0-d212-4b74-811a-67f4ab94bebf/

eaglet | 专家六级 |园豆:17139 | 2009-04-01 06:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册