SQL Server CLR与第三方SDK的集成:缺少装配System.Drawing时出错 [英] SQL Server CLR integration with 3rd party SDK: Error on missing assembly System.Drawing

查看:128
本文介绍了SQL Server CLR与第三方SDK的集成:缺少装配System.Drawing时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一种解决方案,该解决方案将与第三方应用程序的SDK交互,并最终创建一个数据集以将数据迁移到我们的SQL Server 2014实例上的目标数据库中.此接口通过SQL Server CLR存储过程进行.在C#端创建CLR程序集时使用了以下参考:

I am developing a solution that will interface with the SDK of a 3rd party application and ultimately create a dataset to migrate data into a destination database on our SQL Server 2014 instance. This interface is via a SQL Server CLR Stored procedure. the following references have been used in creating the CLR assembly on the C# side:

    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Data.SqlTypes;
    using Microsoft.SqlServer.Server;
    using (3rd party SDK);
    using System.Dynamic;

所有代码均正确构建.但是,当我尝试使用 CREATE ASSEMBLY 语句创建程序集时,出现以下错误:

The code builds correctly and all. However, when I attempt to create an assembly using the CREATE ASSEMBLY statement I get the following error:

程序集"MyAssembly"引用程序集"system.drawing,版本= 4.0.0.0,区域性=中性,publickeytoken = b03f5f7f11d50a3a",当前数据库中不存在该程序集.SQL Server尝试从引用程序集所在的位置查找并自动加载引用的程序集,但该操作失败(原因:2(系统找不到指定的文件.)).请将引用的程序集加载到当前数据库中,然后重试您的请求.

Assembly 'MyAssembly' references assembly 'system.drawing, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.', 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.

更进一步,如果我尝试基于显然缺少的引用system.drawing创建一个不安全的程序集(请记住,我确实在目标数据库中将可信度设置为true),则会出现以下错误:

Going further, if I attempt to create an unsafe assembly based on the apparently missing reference, system.drawing (keep in mind I do have trustworthy set to true in the target database), I get the following error:

为装配"System.Drawing"创建装配失败,因为装配"System.Drawing"验证失败.检查引用的程序集是否最新且受信任(对于external_access或不安全),以便在数据库中执行.CLR验证程序错误消息(如果有)将跟随此消息
[:System.Drawing.Image :: Finalize] [mdToken = 0x600000d] [offset 0x00000000]代码大小为零.(等等,系统错误在不同方法上重复同样的错误)

CREATE ASSEMBLY for assembly 'System.Drawing' failed because assembly 'System.Drawing' failed verification. Check if the referenced assemblies are up-to-date and trusted (for external_access or unsafe) to execute in the database. CLR Verifier error messages if any will follow this message
[ : System.Drawing.Image::Finalize][mdToken=0x600000d][offset 0x00000000] Code size is zero. (etc, etc. same error repeating on different methods in system.drawing)

我已经有解决方案和与v4.0匹配的目标SQL Server数据库之间匹配的.NET框架.老实说,我在这里很茫然,这似乎比应该做的要难得多.我什至没有直接引用System.Drawing,但是出于某种奇怪的原因,我需要它.

I already have the .NET frameworks matching between the solution and the target SQL Server database matching to v4.0. I honestly am at a loss here, and this seems soo much harder than it should be. I'm not even directly referencing System.Drawing, yet I need it for some odd reason.

推荐答案

虽然它可能并不总是按预期方式运行,但您应该能够将 System.Drawing 加载到SQL Server中.您将需要将数据库设置为 TRUSTWORTHY ON (似乎已启用),并且需要在 CREATE ASSEMBLY <中将程序集标记为 UNSAFE ./code>语句(即使用 WITH PERMISSION_SET = UNSAFE 子句).

While it might not always behave as expected, you should be able to load System.Drawing into SQL Server. You will need to set the Database to TRUSTWORTHY ON (which it seems that you have), and you need to mark the Assembly as UNSAFE in the CREATE ASSEMBLY statement (i.e. use the WITH PERMISSION_SET = UNSAFE clause).

如果仍然出现错误,请确保正在加载实际的 System.Drawing DLL,而不是参考程序集之一,并确保获取正确的32位或64位版本.

If you still get an error, make sure you are loading the actual System.Drawing DLL and not one of the reference Assemblies, and make sure you grab the correct 32-bit or 64-bit version.

对于CLR 4.0版(由SQL Server 2012及更高版本使用),汇编路径应为以下两个选项之一,具体取决于您需要的是32位还是64位版本:

For CLR version 4.0 (which is used by SQL Server 2012 and newer), the assembly path should be one of following two options, depending on whether you need the 32-bit or 64-bit version:

  • C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ System.Drawing.dll

C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ System.Drawing.dll

此外,只要使用的是绑定到正确的CLR版本(即4.0)的版本,您就不必担心.NET Framework版本.这意味着,只要目标服务器已更新到该Framework版本,您也可以使用.NET Framework 4.5.2或4.6版本.

Also, you don't need to worry about the .NET Framework version as long as you are using one that is bound to the proper CLR version, which is 4.0. Meaning, you could just as well be using .NET Framework version 4.5.2 or 4.6, so long as the target server has been updated to that Framework version.

这篇关于SQL Server CLR与第三方SDK的集成:缺少装配System.Drawing时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆