SQL Server支持哪种版本的.NET框架?

时间:2021-03-01 14:10:52

I want to create SQLCLR based stored procedures for SQL Server. As you know I can build a dll against multiple versions of .NET framework. I can't find a reference that describe which version of SQL Server supports which version of .NET framework. Can anyone help to point me the right direction?

我想为SQL Server创建基于SQLCLR的存储过程。如您所知,我可以针对多个版本的.NET框架构建一个DLL。我找不到描述哪个版本的SQL Server支持哪个版本的.NET框架的参考。任何人都可以帮我指出正确的方向吗?

1 个解决方案

#1


19  

To be clear, a single version of the CLR typically has multiple versions of the .NET Framework that it works with. A single version of the .NET Framework, however, only works with one specific version of the CLR. For example, CLR version 2.0 works with .NET Framework versions 2.0, 3.0, and 3.5, while CLR version 4.0 works with all of the 4.x versions of the .NET Framework (i.e. 4.0, 4.5[.x], 4.6[.x], 4.7[.x], etc). To see the chart of CLR version to Framework version relationships, see the MSDN page for .NET Framework Versions and Dependencies.

需要明确的是,单个版本的CLR通常具有与其一起使用的多个.NET Framework版本。但是,单个版本的.NET Framework仅适用于CLR的一个特定版本。例如,CLR 2.0版适用于.NET Framework版本2.0,3.0和3.5,而CLR 4.0版适用于.NET Framework的所有4.x版本(即4.0,4.5 [.x],4.6 [。 x],4.7 [.x]等)。要查看CLR版本到Framework版本关系的图表,请参阅.NET Framework版本和依赖关系的MSDN页面。

With regards to SQLCLR code, SQL Server only works with a single version of the CLR, and the specific version depends upon the version of SQL Server. SQL Server 2005, 2008, and 2008 R2 work only with CLR version 2. Since CLR version 2 only works with .NET Framework versions 2.0, 3.0, and 3.5, this means that SQL Server 2005, 2008, and 2008 R2 only work with .NET Framework versions 2.0, 3.0, and 3.5.

关于SQLCLR代码,SQL Server仅适用于单个版本的CLR,特定版本取决于SQL Server的版本。 SQL Server 2005,2008和2008 R2仅适用于CLR版本2.由于CLR版本2仅适用于.NET Framework版本2.0,3.0和3.5,这意味着SQL Server 2005,2008和2008 R2仅适用于。 NET Framework版本2.0,3.0和3.5。

Of course, SQL Server 2005's CLR Integration feature (the initial version of it) was built around .NET Framework version 2.0 (as that is what was available at the time), so there are a couple of newer libraries in .NET Framework versions 3.0 and 3.5 that don't work in SQL Server 2005 without manually importing them (i.e. System.Core and System.Xml.Linq). Along those same lines, SQL Server 2012, 2014, 2016, and 2017 are statically linked to CLR version 4, which works with .NET Framework versions 4.0, 4.5[.x], 4.6[.x], and 4.7[.x].

当然,SQL Server 2005的CLR集成功能(它的初始版本)是围绕.NET Framework 2.0版构建的(因为那是当时可用的),因此.NET Framework 3.0版中有几个较新的库和3.5在没有手动导入它们的情况下在SQL Server 2005中不起作用(即System.Core和System.Xml.Linq)。同样,SQL Server 2012,2014,2016和2017静态链接到CLR版本4,它适用于.NET Framework版本4.0,4.5 [.x],4.6 [.x]和4.7 [.x] 。

With regards to the information returned from both System.Environment.Version (in .NET code) and SELECT [version] FROM sys.dm_clr_properties;, they are reporting the CLR version, not the .NET Framework version. So be careful not to confuse those two things reporting 2.0 or 4.0 as meaning you can only use Framework version 2.0 or 4.0.

关于从System.Environment.Version(在.NET代码中)和SELECT [version] FROM sys.dm_clr_properties;返回的信息,它们报告的是CLR版本,而不是.NET Framework版本。因此,请注意不要将报告2.0或4.0的两件事混淆为意味着您只能使用Framework 2.0或4.0版。

And fortunately, due to backwards compatibility, code compiled against the CLR 2 Framework versions (2.0, 3.0, and 3.5) will run without needing to be recompiled in SQL Server 2012 and newer, even though they are on CLR version 4.

幸运的是,由于向后兼容性,针对CLR 2 Framework版本(2.0,3.0和3.5)编译的代码将运行而无需在SQL Server 2012及更高版本中重新编译,即使它们位于CLR版本4上。

So, you generally cannot go wrong with using a Target Framework Version of 2.0, but you most certainly can use Framework versions beyond 2.0.

因此,使用Target Framework Version 2.0时通常不会出错,但您肯定可以使用2.0之外的Framework版本。

For a more in-depth look at developing SQLCLR code, check out the following article (and the series in general), which I wrote:

有关开发SQLCLR代码的更深入了解,请查看以下文章(以及一般的系列文章),我写道:

Stairway to SQLCLR Level 5: Development (Using .NET within SQL Server)

SQLCLR的阶梯级别5:开发(在SQL Server中使用.NET)

#1


19  

To be clear, a single version of the CLR typically has multiple versions of the .NET Framework that it works with. A single version of the .NET Framework, however, only works with one specific version of the CLR. For example, CLR version 2.0 works with .NET Framework versions 2.0, 3.0, and 3.5, while CLR version 4.0 works with all of the 4.x versions of the .NET Framework (i.e. 4.0, 4.5[.x], 4.6[.x], 4.7[.x], etc). To see the chart of CLR version to Framework version relationships, see the MSDN page for .NET Framework Versions and Dependencies.

需要明确的是,单个版本的CLR通常具有与其一起使用的多个.NET Framework版本。但是,单个版本的.NET Framework仅适用于CLR的一个特定版本。例如,CLR 2.0版适用于.NET Framework版本2.0,3.0和3.5,而CLR 4.0版适用于.NET Framework的所有4.x版本(即4.0,4.5 [.x],4.6 [。 x],4.7 [.x]等)。要查看CLR版本到Framework版本关系的图表,请参阅.NET Framework版本和依赖关系的MSDN页面。

With regards to SQLCLR code, SQL Server only works with a single version of the CLR, and the specific version depends upon the version of SQL Server. SQL Server 2005, 2008, and 2008 R2 work only with CLR version 2. Since CLR version 2 only works with .NET Framework versions 2.0, 3.0, and 3.5, this means that SQL Server 2005, 2008, and 2008 R2 only work with .NET Framework versions 2.0, 3.0, and 3.5.

关于SQLCLR代码,SQL Server仅适用于单个版本的CLR,特定版本取决于SQL Server的版本。 SQL Server 2005,2008和2008 R2仅适用于CLR版本2.由于CLR版本2仅适用于.NET Framework版本2.0,3.0和3.5,这意味着SQL Server 2005,2008和2008 R2仅适用于。 NET Framework版本2.0,3.0和3.5。

Of course, SQL Server 2005's CLR Integration feature (the initial version of it) was built around .NET Framework version 2.0 (as that is what was available at the time), so there are a couple of newer libraries in .NET Framework versions 3.0 and 3.5 that don't work in SQL Server 2005 without manually importing them (i.e. System.Core and System.Xml.Linq). Along those same lines, SQL Server 2012, 2014, 2016, and 2017 are statically linked to CLR version 4, which works with .NET Framework versions 4.0, 4.5[.x], 4.6[.x], and 4.7[.x].

当然,SQL Server 2005的CLR集成功能(它的初始版本)是围绕.NET Framework 2.0版构建的(因为那是当时可用的),因此.NET Framework 3.0版中有几个较新的库和3.5在没有手动导入它们的情况下在SQL Server 2005中不起作用(即System.Core和System.Xml.Linq)。同样,SQL Server 2012,2014,2016和2017静态链接到CLR版本4,它适用于.NET Framework版本4.0,4.5 [.x],4.6 [.x]和4.7 [.x] 。

With regards to the information returned from both System.Environment.Version (in .NET code) and SELECT [version] FROM sys.dm_clr_properties;, they are reporting the CLR version, not the .NET Framework version. So be careful not to confuse those two things reporting 2.0 or 4.0 as meaning you can only use Framework version 2.0 or 4.0.

关于从System.Environment.Version(在.NET代码中)和SELECT [version] FROM sys.dm_clr_properties;返回的信息,它们报告的是CLR版本,而不是.NET Framework版本。因此,请注意不要将报告2.0或4.0的两件事混淆为意味着您只能使用Framework 2.0或4.0版。

And fortunately, due to backwards compatibility, code compiled against the CLR 2 Framework versions (2.0, 3.0, and 3.5) will run without needing to be recompiled in SQL Server 2012 and newer, even though they are on CLR version 4.

幸运的是,由于向后兼容性,针对CLR 2 Framework版本(2.0,3.0和3.5)编译的代码将运行而无需在SQL Server 2012及更高版本中重新编译,即使它们位于CLR版本4上。

So, you generally cannot go wrong with using a Target Framework Version of 2.0, but you most certainly can use Framework versions beyond 2.0.

因此,使用Target Framework Version 2.0时通常不会出错,但您肯定可以使用2.0之外的Framework版本。

For a more in-depth look at developing SQLCLR code, check out the following article (and the series in general), which I wrote:

有关开发SQLCLR代码的更深入了解,请查看以下文章(以及一般的系列文章),我写道:

Stairway to SQLCLR Level 5: Development (Using .NET within SQL Server)

SQLCLR的阶梯级别5:开发(在SQL Server中使用.NET)