title: How to convince sql server 2008r2 to use clr v4.0 instead of v2.0?
body: <p>I have sql server 2008r2. According to my internet research it supports .net framework 4.0. I tried to install my assembly with sql clr functions and receved an error. </p>
  
  <blockquote>
    <p>CREATE ASSEMBLY for assembly 'MyAssembly' failed because the assembly
    is built for an unsupported version of the Common Language Runtime.</p>
  </blockquote>
  
  <p>Query</p>
  
  <pre><code>select * from sys.dm_clr_properties
  </code></pre>
  
  <p>Gives result:</p>
  
  <blockquote>
    <p>directory    C:\Windows\Microsoft.NET\Framework64\v2.0.50727\ </p>
    
    <p>version v2.0.50727</p>
    
    <p>CLR is initialized</p>
  </blockquote>
  
  <p>I check C:\Windows\Microsoft.NET\Framework64\ to be sure and found v4.0.30319 folder where. So, .net v4.0 is installed.</p>
  
  <p>So, I need to change CLR version that used for sql. I tried </p>
  
  <pre><code>sp_configure 'clr enabled', 0;
  GO
  RECONFIGURE;
  GO
  
  sp_configure 'clr enabled', 1;
  GO
  RECONFIGURE;
  GO
  </code></pre>
  
  <p>It did not help. I tried to add sqlservr.exe.config with content </p>
  
  <pre><code>&lt;configuration&gt;
     &lt;startup&gt;
        &lt;requiredRuntime version="v4.0"/&gt;
     &lt;/startup&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>to C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn folder and restart sql server. It didn't help as well.</p>
  
  <p>I know about option with creating registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework\OnlyUseLatestCLR and setting it to 1. It can broke other solutions, so I affraid of using it on production. </p>
  
  <p>Is where any suggestions how to convince sql server to use clr v4.0?</p>
  
  <p><h2>So, the answer is - where is no way to do it.</h2> In my case I lowed the target framework to 3.5 and excluded some clr functions.</p>