c# – 在数据库错误中找不到的SQL Server抛出程序集中创建自定义程序集

我正在尝试为SQL Server 2008中的CLR过程项目创建第三方dll(在.net中开发)的程序集,

create assembly [`XXXX.XXX.XXX.dll`]  
authorization dbo  
from 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\XXXX.XXX.XXX.dll'  
with permission_set = unsafe

但是我在执行上面的脚本时遇到了这个错误:

Assembly ‘XXX.XXX.XXX.XXX’ references assembly ‘XXX.XXX.XXXXX’,
version=0.0.0.0, culture=neutral, publickeytoken=null.’, which is not
present in the current database. SQL Server attempted to locate and
automatically load the referenced assembly from the same location
where referring assembly came from, but that operation has failed
(reason: 2(The system cannot find the file specified.)). Please load
the referenced assembly into the current database and retry your
request.

感谢您帮助解决此问题

解决方法:

您可以将程序集添加到CLR使用的数据库中.

我已将System.Messaging.dll添加到SQL Server 2014,如下所示

CREATE ASSEMBLY [System.Messaging]
FROM 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Messaging.dll'
WITH PERMISSION_SET = UNSAFE;
GO 

它将添加链接到那个的必要的其他引用程序集.之后,我添加了Newtonsoft.Json.dll,如下所示:

CREATE ASSEMBLY [Newtonsoft.Json]
FROM 'C:\Users\RiaanDL\Downloads\Json60r3\Bin\Net45\Newtonsoft.Json.dll'
WITH PERMISSION_SET = UNSAFE;
GO

只需记住在项目配置中将SQLCLR权限级别设置为UNSAFE.

上一篇:MyBatis的参数处理——parameterType 如何配置参数


下一篇:RestTemplate打印日志的正确知识