2012-01-30 14 views
0

最近、私はユーザー名がパラメータとして提供されているユーザーのパスワードを取得するアプリケーションを作成しました。コードをチェックして正常に動作しました。クラスライブラリを作成しました。このassemnbly SQL Server 2008で、私のクラスライブラリのコードは以下のとおりです。私もここでSql-Clrセキュリティ例外

ALTER FUNCTION [dbo].[fn_UserCredentials](@UserName [nvarchar](max)) 
RETURNS [nvarchar](max) WITH EXECUTE AS CALLER 
AS 
EXTERNAL NAME [DNN_USER_CREDENTIALS].[DnnUserCredentials].[GetUserPassword] 

:私は、コマンドが正常にメッセージを完了してしまった

CREATE ASSEMBLY DNN_USER_CREDENTIALS FROM 'E:\NBM SITES\SqlProjectDll (DO NOT DELETE)\UserCredentials.dll' WITH PERMISSION_SET = SAFE 

以下のように

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Web.Security; 

public class DnnUserCredentials 
{ 
    public static string GetUserPassword(string username) 
    { 
     MembershipUser objUser = Membership.GetUser(username); 
     return objUser.GetPassword(); 
    } 
} 

私はその後、私は以下のような関数を作成し、SQL Server 2008でアセンブリを作成しましたコマンドを正常に完了しました。メッセージを受け取ったときに関数を呼び出そうとしました。

SELECT [dbo].[fn_UserCredentials]('host') 

それはエラーの下に私をスロー:

A .NET Framework error occurred during execution of user-defined routine or aggregate "fn_UserCredentials": 
System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. 
System.Security.SecurityException: 
    at DnnUserCredentials.GetUserPassword(String username) 

あらゆるソリューションを提供しています。

答えて

0

何が問題なのかわかりません。最初にPERMISSION_SETをUnrestrictedに変更してください。 これは、Visual StudioからDLLをデバッグするのに役立ちません。

0

リモートリソースにアクセスするには、PERMISSION_SET = UNSAFEを設定する必要があります。 TRUSTWORTHYフラグをONに設定することもできます。

ALTER [<DBName>] SET TRUSTWORTHY ON 
GO 
CREATE ASSEMBLY [<assemblyName>] 
--user with sysadmin rights for this DB may be required for deploing 
AUTHORIZATION [<someSysadmin>] 
FROM '[<pathToDll>]' 
--compiled with unsafe to access EventLog for example 
WITH PERMISSION_SET = UNSAFE 
GO 
関連する問題