I have sql server 2008r2. According to my research on the Internet, it supports the .NET Framework 4.0. I tried to install my assembly using sql clr functions and got an error.
CREATE ASSEMBLY for the assembly "MyAssembly" failed because the assembly was built for an unsupported version of the Common Language Runtime.
Request
select * from sys.dm_clr_properties
It gives the result:
directory C: \ Windows \ Microsoft.NET \ Framework64 \ v2.0.50727 \
version v2.0.50727
CLR initialized
I check C: \ Windows \ Microsoft.NET \ Framework64 \ to be sure and find the folder v4.0.30319 where. So, .net v4.0 is installed.
So, I need to change the CLR version used for sql. I tried
sp_configure 'clr enabled', 0; GO RECONFIGURE; GO sp_configure 'clr enabled', 1; GO RECONFIGURE; GO
It did not help. I tried adding sqlservr.exe.config with content
<configuration> <startup> <requiredRuntime version="v4.0"/> </startup> </configuration>
to the folder C: \ Program Files \ Microsoft SQL Server \ MSSQL10_50.MSSQLSERVER \ MSSQL \ Binn and restart the sql server. It didn’t help either.
I know about the option to create the registry key HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft.NETFramework \ OnlyUseLatestCLR and set it to 1. It may break other solutions, so I'm afraid to use it for production.
Are there any suggestions on how to convince a SQL server to use clr v4.0?
So the answer is where is this not a way to do this.
In my case, I downgraded the target structure to 3.5 and excluded some clr functions.