Search code examples
sql-serversql-server-2012sqlclr.net-framework-version

Is it possible to to add .NET Framework v.2.0 Assembly to SQL Server 2012?


I have a DLL which uses .NET Framework v2.0. and I want to add it to SQL Server 2012 using CREATE ASSEMBLY. But SQL Server 2012 uses .NET Framework v.4.0. Is it possible to add a .NET Framework v2.0 assembly to SQL Server 2012?


Solution

  • Well, it depends. The question title and question text imply two different questions.

    If the question is about a .NET Framework DLL:

    No. SQL Server 2012 and 2014 are statically linked to only CLR version 4.0 (meaning .NET Framework versions starting at 4.0 through at least 4.5.2 if not also 4.6 if that has been released). Hence it is not possible to load any Framework DLL that is part of CLR 2.0 (i.e. Framework versions 2.0, 3.0, and 3.5) into SQL Server 2012 or 2014.

    However, everything should be backwards compatible and should work just the same if you try to load the CLR 4.0 (i.e. Framework versions 4.0, 4.5, 4.5.1, etc) version of the same Framework DLL. The only reason why this wouldn't work is if the DLL in question, or one of its dependencies, changed to become a mixed-mode DLL in one of the Framework updates that was released after the version that you have been using. The problem in that case would be that SQL Server only supports pure MSIL DLLs.

    If the question is about a DLL that you created:

    Again, as long as it is not a mixed-mode DLL, everything should be backwards compatible and should work just the same.

    If loading the DLL errors with:

    Assembly "{AssemblyName}" was built using version vX.Y.ZZZZ of the .NET Framework. SQL Server currently uses version v4.0.30319

    then you can probably re-link it to 4.0. Please see my answer to "Cannot register stdole assembly in SQL Server 2012" for an example of doing this.


    FYI, I wrote an article that explains the CLR / Framework versions issue in detail: Stairway to SQLCLR Level 5: Development (Using .NET within SQL Server) (free registration required).