0

私は Visual C# 2010 との SQLCLR 統合に取り組んでいます。私がやろうとしているのは、いくつかの画像、私の関数を含むフォルダーがあり、フォルダー内のファイルを反復処理し、高さ幅などの基本的なファイル情報を取得することです。 ..

Visual C# 2010 から dll を作成し、Sql Server 2008 にアセンブリとして追加し、関数も作成しましたが、関数を選択しようとすると、以下のエラーが発生します。

A .NET Framework error occurred during execution of user-defined routine or aggregate "fn_GetFiles":   
System.Security.SecurityException: Request failed.  
System.Security.SecurityException:   
   at UserDefinedFunctions.GetFileList(String FolderPath)  
   at UserDefinedFunctions.GetFileInfo(String folderPath)

以下は私の.net関数です..

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]  
public partial class UserDefinedFunctions  
{  
    [SqlFunction(FillRowMethodName = "FillRow")]  
    public static IEnumerable GetFileInfo(string folderPath)  
    {  
        // Put your code here
        return GetFileList(folderPath);
    }

    public static ArrayList GetFileList(string FolderPath)
    {
        ArrayList li = new ArrayList();
        foreach (String s in Directory.GetFiles(FolderPath, "*.jpg"))
        {
            FileInfo info = new FileInfo(s);
            object[] column = new object[3];
            column[0] = Path.GetFileName(s);
            column[1] = info.Length;
            column[2] = s;

            li.Add(column);
        }
        return li;
    }

    private static void FillRow(Object obj, out string filename, out string fileSize, out string filePath)
    {
        object[] row = (object[])obj;
        filename = (string)row[0];
        fileSize = (string)row[1];
        filePath = (string)row[2];
    }

};

SQLサーバーでアセンブリを作成する方法は次のとおりです..

CREATE assembly GetFileList from 'E:\NBM Sites\DontDelete\SampleCLRIntegration.dll' with permission_set = safe

以下のようなSQL関数を作成しました。

ALTER FUNCTION fn_GetFiles   
(  
    @folderPath nvarchar(max)  
)  
RETURNS TABLE   
(  
    [filename] nvarchar(max),  
    fileSize nvarchar(max),  
    filePath nvarchar(max)  
)  
AS EXTERNAL NAME GetFileList.UserDefinedFunctions.GetFileInfo;  

以下のような関数を呼び出します。

select * from dbo.fn_GetFiles('E:\NBM Sites\DontDelete')

このエラーを修正するにはどうすればよいですか?

4

1 に答える 1

0

「SAFE」権限セットではなく「外部アクセス」が必要です。見る:

http://msdn.microsoft.com/en-us/library/ms345106.aspx

試す:

permit_set=EXTERNAL_ACCESSを使用 
于 2011-06-17T20:06:33.093 に答える