首页 新闻 会员 周边 捐助

sql注册程序集(无法安装程序集***,因为现有策略阻止使用它。)

0
悬赏园豆:20 [已解决问题] 解决于 2013-01-25 14:48
--开启CLR
exec sp_configure 'show advanced options', '1';
go
reconfigure;
go
exec sp_configure 'clr enabled', '1'
go
reconfigure;
exec sp_configure 'show advanced options', '1';

go 


use DB_Test

--配置SA数据权限
alter database DB_TEST set TRUSTWORTHY  on
EXEC sp_changedbowner 'sa'



--创建程序集 

create  ASSEMBLY MSExcel  FROM   'C:\sql\Microsoft.Office.Interop.Excel.dll'  --如:F:\InterfaceFile\Easyway.ISP.Proxy.dll
WITH PERMISSION_SET =  unSAFE;
go

create  ASSEMBLY EXCELTEST  FROM   'C:\sql\excelDS.dll'  --如:F:\InterfaceFile\Easyway.ISP.Proxy.dll
WITH PERMISSION_SET =  unSAFE;
go

我注册程序集的时候,如果只有一个单纯的dll是可以注册上的,如果是dll调用其他dll的话就不能进行注册,并报错
"消息 6586,级别 16,状态 1,第 1 行
无法安装程序集 'XXXX',因为现有策略阻止使用它。
"

苹果的飞天猪的主页 苹果的飞天猪 | 初学一级 | 园豆:57
提问于:2012-05-23 21:41
< >
分享
最佳答案
0

参考一下Problem in registering external dll using Create Assembly中提到的方法:

--Drop all the things previously created

USE Warehouse

DROP FUNCTION Permissions

DROP ASSEMBLY assembly1

DROP LOGIN CLRLogin

DROP ASSEMBLY SystemDirectoryServices

USE master

DROP ASYMMETRIC KEY asymmetrickey1

 

--Create key pair file for signing. At a command prompt, call sn.exe (in the Visual Studio 8 bin folder)

-- sn -k mykeypair.snk

--Create Visual Studio project. Write class. Sign code (project properties) using the snk file created.

--Then import the dll.....

--Enable the CLR in the database

sp_configure 'show advanced options', 1;

GO

RECONFIGURE;

GO

sp_configure 'clr enabled', 1;

GO

RECONFIGURE;

GO 

ALTER DATABASE Warehouse SET TRUSTWORTHY ON

USE master

CREATE ASYMMETRIC KEY asymmetrickey1 FROM EXECUTABLE FILE = 'E:\Databases\CLR\PermissionsCLR.dll'

CREATE LOGIN CLRLogin FROM ASYMMETRIC KEY asymmetrickey1

GRANT UNSAFE ASSEMBLY TO CLRLogin --GRANT EXTERNAL ACCESS ASSEMBLY TO SQLCLRTestLogin

USE Warehouse

CREATE ASSEMBLY SystemDirectoryServices FROM 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.DirectoryServices.dll' WITH PERMISSION_SET = UNSAFE

CREATE ASSEMBLY assembly1 FROM 'E:\Databases\CLR\PermissionsCLR.dll' WITH PERMISSION_SET = UNSAFE --EXTERNAL_ACCESS

CREATE FUNCTION Permissions(@username nvarchar(100))

RETURNS TABLE ([Property_Code] [nchar](5))

AS EXTERNAL NAME assembly1.[PermissionsCLR.Permissions].InitMethod

SELECT * FROM Permissions(dbo.UserName()) order by property_code
收获园豆:20
dudu | 高人七级 |园豆:30925 | 2012-05-23 22:13
其他回答(1)
0

没搞定-_-

涛神依旧 | 园豆:202 (菜鸟二级) | 2020-10-21 16:04
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册