--开启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',因为现有策略阻止使用它。
"
参考一下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
没搞定-_-