【发布时间】:2015-02-01 21:52:37
【问题描述】:
我在用于创建程序集的服务器上的文件夹中有一个包含 3 个 dll 文件的文件夹。我一开始尝试了以下代码并得到一个错误,说它在服务器上找不到 system.data.datasetextensions.dll 文件,我将 dll 从我的计算机复制并粘贴到我的 clr 项目所在的同一文件夹中并尝试再次运行该命令。
Create Assembly OoplesCLR from 'c:\ooplesclr\OoplesFinanceCLR.dll' with Permission_set = SAFE
GO
将 dll 从我的计算机复制到服务器文件夹后,我现在收到此错误
Warning: The Microsoft .NET Framework assembly 'system.data.datasetextensions, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089.' you are registering is not fully tested in the SQL Server hosted environment and is not supported. In the future, if you upgrade or service this assembly or the .NET Framework, your CLR integration routine may stop working. Please refer SQL Server Books Online for more details.
Msg 6218, Level 16, State 2, Line 1
CREATE ASSEMBLY for assembly 'OoplesFinanceCLR' failed because assembly 'System.Data.DataSetExtensions' 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.Data.DataRowComparer::get_Default][mdToken=0x6000001][offset 0x00000000] Code size is zero.
[ : System.Data.DataRowComparer`1[TRow]::Equals][mdToken=0x6000004][offset 0x00000000] Code size is zero.
[ : System.Data.DataRowComparer`1[TRow]::GetHashCode][mdToken=0x6000005][offset 0x00000000] Code size is zero.
[ : System.Data.DataRowComparer`1[TRow]::.cctor][mdToken=0x6000006][offset 0x00000000] Code size is zero.
[ : System.Data.DataRowComparer`1[TRow]::.ctor][mdToken=0x6000002][offset 0x00000000] Code size is zero.
[ : System.Data.DataRowComparer`1[TRow]::get_Default][mdToken=0x6000003][offset 0x00000000] Code size is zero.
[ : System.Data.DataTableExtensions::CopyToDataTable[T]][mdToken=0x6000008][offset 0x00000000] Code size is zero.
[ : System.Data.DataTableExtensions::CopyToDataTable[T]][mdToken=0x6000009][offset 0x00000000] Code size is zero.
[ : System.Data.DataTableExtensions::CopyToDataTable[T]][mdToken=0x600000a][offset 0x00000000] Code size is zero.
[ : System.Data.DataTableExtensions::AsDataView[T]][mdToken=0x600000c][offset 0x00000000] Code size is zero.
[ : System.Data.DataTableExtensions::AsEnumerable][mdToken=0x6000007][offset 0x00000000] Code size is zero.
[ : System.Data.DataTableExtensions::AsDataView][mdToken=0x600000b][offset 0x00000000] Code size is zero.
[ : System.Data.EnumerableRowCollection::System.Collections.IEnumerable.GetEnumerator][mdToken=0x600000e][offset 0x00000000] Code size is zero.
[ : System.Data.EnumerableRowCollection::.ctor][mdToken=0x600000d][offset 0x00000000] Code size is zero.
[ : System.Data.EnumerableRowCollection`1[TRow]::System.Collections.IEnumerable.GetEnumerator][mdToken=0x600000f][offset 0x00000000] Code size is zero.
我做错了什么,我该如何解决?
更新 1:我将数据库更改为可信任,然后运行此命令,我得到了同样的错误:
使用 Permission_set = UNSAFE 从“c:\ooplesclr\System.Data.DataSetExtensions.dll”创建程序集 DataSetExtensions 去吧
更新 2:尝试在同一个数据库上创建一个函数来运行程序集。我的用户定义函数是这样的:
public partial class UserDefinedFunctions
{
[SqlFunction]
public static SqlString CalculateInfo()
{
// first get data from the tables and then process the data
getData();
// Put your code here
return new SqlString ("test");
}
更新 3:我使用以下代码创建了没有任何警告或错误的函数,但我无法运行它,因为它说不存在这样的存储过程...
GO
CREATE FUNCTION [dbo].[CalculateInfo]
( )
RETURNS NVARCHAR (MAX)
AS
EXTERNAL NAME [OoplesCLR].[UserDefinedFunctions].[CalculateInfo]
更新 4:即使它说不存在这样的存储过程,我还是设法运行它并且我收到以下错误:
Msg 6522, Level 16, State 1, Line 4
在执行用户定义的例程或聚合“CalculateInfo”期间发生 .NET Framework 错误: System.Security.HostProtectionException: 试图执行 CLR 主机禁止的操作。
The protected resources (only available with full trust) were: All
The demanded resources were: Synchronization, ExternalThreading
System.Security.HostProtectionException:
at UserDefinedFunctions.getData()
at UserDefinedFunctions.CalculateInfo()
如何解决这个异常?
【问题讨论】:
-
问题有问题吗?我假设第一段中提到的错误是您在第二段中将该 DLL 复制到带有 SQLCLR DLL 的文件夹后得到的,对吧?这将部署在什么版本的 SQL Server 上?
-
@srutzky 是的,直到现在我才注意到问题出了问题。但是是的,你是对的
标签: c# sql .net sql-server sqlclr