首页 > 解决方案 > 在 SQL Server 中调用 .NET Standard DLL

问题描述

我有一个从 T-SQL 运行 .NET Standard 项目的要求。我发现这方面的信息很少。我已将 TRUSTWORTHY 设置为 ON。

导入测试程序 dll 我收到以下错误。 导入 test.dll 错误

C:\Program Files\dotnet\sdk\2.2.103\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\我尝试从文件夹中导入 netstandard.dll 。这失败并出现以下错误。但即使从同一个文件夹导入 System.Data.Common 后,我仍然收到以下错误。

导入 netstandard.dll 错误

C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.3\build\netstandard2.0\ref文件夹中导入 netstandard.dll 时,我没有收到任何错误。但是,在调用该函数时,我收到以下错误。

Msg 10313, Level 16, State 51, Line 17
An error occurred while using the .NET Framework during IL compilation. The server may be running out of resources. Try running the query again. If the problem persist, contact a support professional. 
System.IO.FileLoadException: Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Assembly in host store has a different signature than assembly in GAC. (Exception from HRESULT: 0x80131050) See Microsoft Knowledge Base article 949080 for more information.
System.IO.FileLoadException: 
   at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
   at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)

.NET Framework 程序集正常工作。SQL Server 是否支持运行 .NET Standard 程序集?如果不支持,解决方法是什么?有没有比通过 .NET Framework 调用 Web 服务并让 Web 服务调用 .NET Standard 代码更简单的解决方案?

标签: c#sql-servertsql

解决方案


SQL Server 支持 .NET Framework 4 程序集,使用https://docs.microsoft.com/en-us/sql/relational-databases/clr-integration/database-objects/supported-net-framework-libraries 中列出的某些库?视图=sql-server-2017

有关 SQL Server 中 CLR 的最新“新增功能”页面仅提及 SQL Server 2012 中添加的功能:https ://docs.microsoft.com/en-us/sql/relational-databases/clr-integration/clr-integration-what -s-new?view=sql-server-2017

.NET Core 和 .NET Standard 是较新的东西(分别于 2014 年和 2016 年推出)。


推荐阅读