SQLCLR 使用了错误版本的 .NET Framework
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2781624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLCLR using the wrong version of the .NET Framework
提问by Tobias Rundbom
During a recent restart of our development server the SQL Serverstarted using .NET 4.0for the SQLCLR. This means that nothing using the CLR in SQL works, or at least that's my understanding by reading these sources:
在我们的开发服务器最近重新启动期间,SQL Server开始使用.NET 4.0SQLCLR。这意味着在 SQL 中使用 CLR 没有任何效果,或者至少这是我通过阅读这些来源的理解:
http://software.intel.com/en-us/blogs/2009/10/16/sql-server-2008-sqlclr-net-framework-version/
http://software.intel.com/en-us/blogs/2009/10/16/sql-server-2008-sqlclr-net-framework-version/
www.sqlskills.com/BLOGS/BOBB/post/On-SQL-Server-and-NET-40.aspx
www.sqlskills.com/BLOGS/BOBB/post/On-SQL-Server-and-NET-40.aspx
All we get are error messages of this type:
我们得到的只是这种类型的错误消息:
Msg 6517, Level 16, State 1, Line 1 Failed to create AppDomain "xxx.dbo[ddl].3". Method's type signature is not Interop compatible.
消息 6517,级别 16,状态 1,第 1 行无法创建 AppDomain“xxx.dbo[ddl].3”。方法的类型签名与互操作不兼容。
Running the statement (as suggested by @john-christensen)
运行语句(如@john-christensen 所建议)
select * from sys.dm_clr_properties
results in the following information:
产生以下信息:
*Name* *Value*
directory C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
version v4.0.30319
state CLR is initialized
Does anyone know how to solve this or how we can force SQL Server CLR to use an earlier version of the Framework?
有谁知道如何解决这个问题,或者我们如何强制 SQL Server CLR 使用早期版本的框架?
采纳答案by MicSim
Typically you can force a .NET application to use a specific .NET Framework version by specifying the supportedRuntimetag in the application's config file.
通常,您可以通过supportedRuntime在应用程序的配置文件中指定标记来强制 .NET 应用程序使用特定的 .NET Framework 版本。
So you could try creating a sqlservr.exe.configin the \Binnfolder under the root path of the SQL instance and specify there that you would like to use only .NET versions up to 3.5. Check this MSDN linkfor the structure of the config file.
因此,您可以尝试在 SQL 实例根路径下sqlservr.exe.config的\Binn文件夹中创建一个,并在那里指定您只想使用 .NET 版本高达 3.5。检查此 MSDN 链接以了解配置文件的结构。
回答by Hans
I experienced the same annoying problem. None of the Geography/Geometry stuff in my database worked. Took me some unsuccesfull reinstalls of SQL server to finally (some weeks later!) find the following key in my registry had been set to '1'
我遇到了同样烦人的问题。我的数据库中的地理/几何内容都不起作用。花了我一些不成功的 SQL 服务器重新安装,终于(几周后!)发现我的注册表中的以下项已设置为“1”
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\OnlyUseLatestCLR
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\OnlyUseLatestCLR
when I reset it to '0', and rebooted the machine, things worked again!
当我将其重置为“0”并重新启动机器时,一切又恢复了!
Hans
汉斯
回答by John Christensen
From the article and my research on the web, it looks like the opposite might be happening - could you potentially be registering a 4.0 DLL? It appears that SQL Server 2008 will always load the 2.0 CLR and not the 4.0 CLR. Try running this statement, it will tell you what version your SQL server is running:
从这篇文章和我在网上的研究来看,看起来可能会发生相反的情况 - 您可能会注册 4.0 DLL吗?似乎 SQL Server 2008 将始终加载 2.0 CLR 而不是 4.0 CLR。尝试运行此语句,它会告诉您 SQL 服务器正在运行的版本:
select * from sys.dm_clr_properties
从 sys.dm_clr_properties 中选择 *
回答by marc_s
In your post at Intel that you reference, if you read it closely, it says:
在您引用的英特尔帖子中,如果您仔细阅读,它会说:
SQL Server 2008 and the forthcoming SQL Server 2008 R2 release, previously codenamed "Kilimanjaro", will both continue to load the latest service release of the version 2.0 CLR.
SQL Server 2008 和即将发布的 SQL Server 2008 R2 版本(以前代号为“Kilimanjaro”)都将继续加载 2.0 CLR 版本的最新服务版本。
And later on:
后来:
While future versions of SQL Server may load newer versions of the CLR, or even support the loading of multiple CLR's within the process, version 2.0 of the CLR is here to stay for SQLCLR within SQL Server 2008 and SQL Server 2008 R2.
虽然 SQL Server 的未来版本可能会加载更新版本的 CLR,甚至支持在进程中加载多个 CLR ,但 CLR 2.0 版将继续用于 SQL Server 2008 和 SQL Server 2008 R2 中的 SQLCLR。
I don't know how you manage to get something like .NET 4 loaded inside SQL Server 2008 R2....
我不知道您如何设法在 SQL Server 2008 R2 中加载 .NET 4 之类的东西....
回答by Two Bit Gangster
They made explicit choices to ensure that installation of .NET 4.0 would be non-impactful. It shouldn't be using .NET 4.0 or any of the new files except for the new shim files, mscoree.dll and mscoreei.dll. Those should be backward compatible with the 2.0 runtime. You could run Process Explorer to see the version numbers of the dll's loaded to verify that it is running the right runtime.
他们做出了明确的选择,以确保 .NET 4.0 的安装不会产生影响。它不应使用 .NET 4.0 或任何新文件,除了新的 shim 文件 mscoree.dll 和 mscoreei.dll。这些应该与 2.0 运行时向后兼容。您可以运行 Process Explorer 以查看加载的 dll 的版本号,以验证它是否正在运行正确的运行时。
回答by hamed
I had this problem for a day and after updating my windows and .NET frameworks problem disappeared.the problem relates to .Net framework try to repair it.
我有这个问题一天,更新我的 windows 和 .NET 框架后问题消失了。问题与 .Net 框架有关,尝试修复它。

