I am using the below code for CLR stored procedure creation. While I am creating the assembly. it shows the below issue. My target framework is 4.0. sql server is 2008 r2
我正在使用以下代码创建CLR存储过程。我正在创建程序集。它显示了以下问题。我的目标框架是4.0。 sql server是2008 r2
SQL code:
SQL代码:
create assembly SampleSearch from 'E:\CLR Files\Sample\ElasticSearch.dll'
error message:
错误信息:
CREATE ASSEMBLY for assembly 'ElasticSearch' failed because the assembly is built for an unsupported version of the Common Language Runtime.
程序集“ElasticSearch”的CREATE ASSEMBLY失败,因为程序集是为不支持的公共语言运行时版本构建的。
3 个解决方案
#1
19
Microsoft SQL Server does not allow for mixed-mode CLR. Meaning, it is statically linked to a particular version of the CLR (which is not the same thing as the .NET Framework that most people confuse it for). SQL Server 2005, 2008, and 2008 R2 are linked to CLR version 2.0 which handles .NET Framework versions 2.0, 3.0, and 3.5, while SQL Server 2012 and 2014 are linked to CLR version 4.0 which handles .NET Framework versions 4.0, 4.5.x, 4.6.x, etc.
Microsoft SQL Server不允许混合模式CLR。意思是,它静态链接到特定版本的CLR(这与.NET Framework不同,大多数人都把它混淆了)。 SQL Server 2005,2008和2008 R2链接到处理.NET Framework版本2.0,3.0和3.5的CLR 2.0版,而SQL Server 2012和2014链接到处理.NET Framework 4.0,4.5的CLR 4.0版。 x,4.6.x等
You can either:
你可以:
- Recompile using a lower framework version, but if you are using functionality that started in .NET Framework version 4.0 or above then that won't work. Using .NET Framework 2.0 is always the safest bet for SQL Server 2005 - 2008 R2. If you need to use .NET Framework 3.0 or 3.5 for functionality that is not in 2.0 (and not in the list of supported .NET Framework libraries), then you will need to also register the appropriate .NET Framework 3.0 / 3.5 DLL in SQL Server as
UNSAFE
, and doing that requires setting the database option forTRUSTWORTHY
toON
(which is best left asOFF
if at all possible). - 使用较低的框架版本重新编译,但如果您使用的是在.NET Framework 4.0或更高版本中启动的功能,那么这将无效。使用.NET Framework 2.0始终是SQL Server 2005 - 2008 R2最安全的选择。如果您需要将.NET Framework 3.0或3.5用于不在2.0中的功能(而不是在受支持的.NET Framework库列表中),那么您还需要在SQL中注册相应的.NET Framework 3.0 / 3.5 DLL服务器为UNSAFE,这样做需要将TRUSTWORTHY的数据库选项设置为ON(如果可能的话,最好保留为OFF)。
- Upgrade to either SQL Server 2012, 2014, or 2016.
- 升级到SQL Server 2012,2014或2016。
For more detailed info on the topic of .NET nuances within SQL Server (i.e. SQLCLR), please see the following article that I wrote on SQL Server Central, if not the entire series:
有关SQL Server中的.NET细微差别(即SQLCLR)主题的更多详细信息,请参阅我在SQL Server Central上编写的以下文章,如果不是整个系列:
Stairway to SQLCLR Level 5: Development (Using .NET within SQL Server) (free registration is required by that site)
SQLCLR的阶梯级别5:开发(在SQL Server中使用.NET)(该站点需要免费注册)
#3
0
Set the target framework to 2.0 and then try again.
将目标框架设置为2.0,然后再试一次。
#1
19
Microsoft SQL Server does not allow for mixed-mode CLR. Meaning, it is statically linked to a particular version of the CLR (which is not the same thing as the .NET Framework that most people confuse it for). SQL Server 2005, 2008, and 2008 R2 are linked to CLR version 2.0 which handles .NET Framework versions 2.0, 3.0, and 3.5, while SQL Server 2012 and 2014 are linked to CLR version 4.0 which handles .NET Framework versions 4.0, 4.5.x, 4.6.x, etc.
Microsoft SQL Server不允许混合模式CLR。意思是,它静态链接到特定版本的CLR(这与.NET Framework不同,大多数人都把它混淆了)。 SQL Server 2005,2008和2008 R2链接到处理.NET Framework版本2.0,3.0和3.5的CLR 2.0版,而SQL Server 2012和2014链接到处理.NET Framework 4.0,4.5的CLR 4.0版。 x,4.6.x等
You can either:
你可以:
- Recompile using a lower framework version, but if you are using functionality that started in .NET Framework version 4.0 or above then that won't work. Using .NET Framework 2.0 is always the safest bet for SQL Server 2005 - 2008 R2. If you need to use .NET Framework 3.0 or 3.5 for functionality that is not in 2.0 (and not in the list of supported .NET Framework libraries), then you will need to also register the appropriate .NET Framework 3.0 / 3.5 DLL in SQL Server as
UNSAFE
, and doing that requires setting the database option forTRUSTWORTHY
toON
(which is best left asOFF
if at all possible). - 使用较低的框架版本重新编译,但如果您使用的是在.NET Framework 4.0或更高版本中启动的功能,那么这将无效。使用.NET Framework 2.0始终是SQL Server 2005 - 2008 R2最安全的选择。如果您需要将.NET Framework 3.0或3.5用于不在2.0中的功能(而不是在受支持的.NET Framework库列表中),那么您还需要在SQL中注册相应的.NET Framework 3.0 / 3.5 DLL服务器为UNSAFE,这样做需要将TRUSTWORTHY的数据库选项设置为ON(如果可能的话,最好保留为OFF)。
- Upgrade to either SQL Server 2012, 2014, or 2016.
- 升级到SQL Server 2012,2014或2016。
For more detailed info on the topic of .NET nuances within SQL Server (i.e. SQLCLR), please see the following article that I wrote on SQL Server Central, if not the entire series:
有关SQL Server中的.NET细微差别(即SQLCLR)主题的更多详细信息,请参阅我在SQL Server Central上编写的以下文章,如果不是整个系列:
Stairway to SQLCLR Level 5: Development (Using .NET within SQL Server) (free registration is required by that site)
SQLCLR的阶梯级别5:开发(在SQL Server中使用.NET)(该站点需要免费注册)
#2
#3
0
Set the target framework to 2.0 and then try again.
将目标框架设置为2.0,然后再试一次。