简体   繁体   English

Sql 服务器 CLR 加载组件失败

[英]Sql Server CLR load assembly failed

I am trying to deploy an CLR TVF (table value function).我正在尝试部署 CLR TVF(表值函数)。 In the code I am using JavaScriptSerializer to parse some JSON string, so I reference the System.Web.Extensions dll and my problems start there.在代码中,我使用 JavaScriptSerializer 解析一些 JSON 字符串,所以我引用 System.Web.Extensions dll 和我的问题开始。

Project builds fine, but when I try to register the dll I receive the following error:项目构建良好,但是当我尝试注册 dll 时,我收到以下错误:

Assembly 'my_assembly_name' references assembly 'system.web.extensions, version=4.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35.', which is not present in the current database.程序集“my_assembly_name”引用程序集“system.web.extensions, version=4.0.0.0,culture=neutral, publickeytoken=31bf3856ad364e35.”,当前数据库中不存在该程序集。 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.)). SQL 服务器试图从引用程序集所在的同一位置定位并自动加载引用程序集,但该操作失败(原因:2(系统找不到指定的文件。))。 Please load the referenced assembly into the current database and retry your request.请将引用的程序集加载到当前数据库中,然后重试您的请求。

I referenced system.web.extensions from:我引用了 system.web.extensions 来自:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Web.Extensions.dll C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Web.Extensions.Z06416233FE5EC4C8133122E4ZAB2

I can set copy load to true or manually copy the assembly but then referencing errors go deeper -我可以将复制加载设置为 true 或手动复制程序集,但随后更深地引用错误 go -

Assembly 'my_assembly_name' references assembly 'system.servicemodel.activation, version=4.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35.', which is not present in the current database.程序集 'my_assembly_name' 引用程序集 'system.servicemodel.activation, version=4.0.0.0,culture=neutral, publickeytoken=31bf3856ad364e35.',当前数据库中不存在该程序集。 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.)). SQL 服务器试图从引用程序集所在的同一位置定位并自动加载引用程序集,但该操作失败(原因:2(系统找不到指定的文件。))。 Please load the referenced assembly into the current database and retry your request.请将引用的程序集加载到当前数据库中,然后重试您的请求。

Everything works fine until I reference the Web.Extensions.dll.一切正常,直到我引用 Web.Extensions.dll。 Target Framework is .NET 4.目标框架是 .NET 4。

Any ideas/solutions?有什么想法/解决方案吗?

Acording to the documentation, any .NET assembly can be referenced but each dependant assembly must also be registered in the database (visible in the "Programmability - Assemblies" node in SQL Server Manager).根据文档,可以引用任何 .NET 程序集,但每个依赖程序集也必须在数据库中注册(在 SQL 服务器管理器的“可编程性 - 程序集”节点中可见)。 Once the SQL Server Database has the dependant assemblies available they will be present in the Add Reference Dialog window in Visual Studio.一旦 SQL 服务器数据库具有可用的依赖程序集,它们将出现在 Visual Studio 的“添加引用”对话框 window 中。

This SQL code below works.下面的 SQL 代码有效。 I had needed the System.Web.dll assembly (you need the correct version my 2005 SQL is 64 bit)我需要 System.Web.dll 组件(您需要正确的版本,我的 2005 SQL 是 64 位)

CREATE ASSEMBLY [System.Web] AUTHORIZATION dbo 
FROM 'c:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\System.web.dll'
WITH PERMISSION_SET = UNSAFE 

The system will try to automatically register dependent assemblies but can only do it from the same directory as the file you are attempting to register.系统将尝试自动注册依赖程序集,但只能从与您尝试注册的文件相同的目录中进行。 In my case it also registered the following assemblies in the database for System.Web to operate correctly...在我的情况下,它还在数据库中注册了以下程序集,以便 System.Web 正常运行......

System.Configuration.Install    
System.Design   
System.DirectoryServices    
System.DirectoryServices.Protocols  
System.Drawing  
System.Drawing.Design   
System.EnterpriseServices   
System.Runtime.Remoting 
System.Runtime.Serialization.Formatters.Soap    
System.ServiceProcess   
System.Web.RegularExpressions   
System.Windows.Forms

My system is using 3.5 Framework so I cannot test importing System.Web.Extensions.dll for you but it may require other assemblies from another folder to register, and since it is a 4.0 assembly it may be referencing some 2.0 or 3.5 assemblies that are in a different folder.我的系统使用的是 3.5 框架,因此我无法测试导入 System.Web.Extensions.dll 为您但它可能需要其他文件夹中的其他程序集才能注册,并且由于它是 4.0 程序集,它可能引用了一些 2.0 或 3.5 程序集在不同的文件夹中。

I suspect you will end up with a rather large list of assemblies imported to get it to work but it is definitly possible to do.我怀疑您最终会得到一个相当大的导入程序集列表以使其工作,但这绝对是可能的。 The operation can probably be done more easily by having one folder with all the dependent dlls in it and register from there.通过拥有一个包含所有相关 dll 的文件夹并从那里注册,该操作可能会更容易完成。

Sadly integration of the .NET Framework CLR with SQL Server 2005 / 2008 is only a limited subset of the framework and the System.Web.Extensions doesn't seem to be a supported assembly / namespace.遗憾的是,.NET 框架 CLR 与 SQL Server 2005 / 2008 的集成只是框架的一个有限子集,并且 System.ZC6E190B284633C48E39E55049Ex3CCE8Z 似乎是受支持的程序集/命名空间。

For a full list of supported assemblies check out MSDN: http://msdn.microsoft.com/en-us/library/ms403279.aspx有关受支持程序集的完整列表,请查看 MSDN: http://msdn.microsoft.com/en-us/library/ms403279.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM