SQL Server Management Studio 2012 .NET Framework 4.0 running stored procedure SSIS package targeting .NET 4.5 - sql-server

How do I change the .NET framework of MS SQL Server 2012?
I have a SSIS package that has a script that cannot target .NET 4.0 due to using WebUtility.UrlEncode().
Will upgrading to 4.5 on the Server interfere with other stored procedures that are currently running (and targeting 4.0)?
I tried setting the target of the Script Task to 4.0 but WebUtility.UrlEncode isnt available for 4.0.

Two things at play here.
The first is the target setting for the SSIS Script Task/Component. You can change that up/down as the item requires.
That's a development setting by the way. When you deploy to the server, would need to ensure that server itself has an equivalent runtime on it.
Now, things get "weird" because for the 4.0 runtime framework, which we both have, there are developer versions within that version, from a Command Prompt if you typed
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe you'd see what version there. For example, I see
Microsoft (R) Visual C# Compiler version 4.8.4084.0 for C# 5
How do I find the .NET version?

Related

RS.exe utility still targets .Net 3.5?

I have installed SQL Server 2016 Standard along with SSRS 2017. I am using rs.exe tool for SSRS reports deployment.
When I try to execute rs.exe from command line, I am prompted to install .Net framework 3.5. While tool works after .Net FW 3.5 is installed - this is not something I want to do.
I have searched for similar questions and found out only this: https://social.msdn.microsoft.com/Forums/en-US/334685df-8899-4a53-9513-0b443fc485fe/rsexe-depends-on-net-35-but-sql-server-reporting-services-2017-system-reqs-dont-mention-it?forum=sqlreportingservices.
Also, no .Net framework 3.5 is listed in system requirements for Sql Server 2016 or SSRS 2017 (https://learn.microsoft.com/bs-cyrl-ba/sql/sql-server/install/hardware-and-software-requirements-for-installing-sql-server?view=sql-server-2016#hwswr)
So I wanted to ask:
Has anyone experienced the same situation? Do you need to actually install old .Net framework(2.0+3.5) to use that tool?
Any workarounds?

Building SQL CLR project in Visual Studio 2015

I am attempting to build a SQL CLR project in Visual Studio 2015 and I am calling a wcf service which targets the System.Runtime.Serialization.dll. I am having problems identifying the correct version of .NET to target in order to overcome this.
The sql version is:
name value
directory C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
version v4.0.30319
state CLR is initialized
I attempted to build the CLR against .NET version 4.
SQL refuses to install System.Runtime.Serialization.dll If I build against .NET version 3.5, I get
Msg 6586, Level 16, State 1, Line 8
Assembly 'System.Runtime.Serialization' could not be installed because existing policy would keep it from being used.
What version should I build against to overcome this?
SQL Server 2012 and newer uses CLR 4.0, which in turn is tied to .NET Framework versions 4.0 and above. You cannot use any .NET 2.0, 3.0, or 3.5 libraries in SQL Server 2012 or newer.
System.Runtime.Serialization is not in the Supported .NET Framework Libraries list, so you need to load it manually, and as UNSAFE. However, if that DLL is mixed mode and not pure MSIL, then it won't load since SQL Server's CLR host only works with pure MSIL libraries. I have found it best to just use HttpWebRequest and build the request XML manually and parse the response XML manually.
In the past, the ServiceModel DLL, and all of its dependencies, were pure MSIL and worked in SQL Server 2008 R2 (SQL Server 2005, 2008, and 2008 R2 are tied to CLR 2.0). But then, in CLR version 4.0, Microsoft added some dependencies to ServiceModel. One of them was the new Microsoft.VisualBasic.Activities.Compiler library (not a direct dependency, but via another, most likely Microsoft.Transactions.Bridge), which happens to contain unmanaged code (which cannot be loaded into SQL Server). Hence, everyone who had working WebService SQLCLR stuff running in 2008 R2 had it stop working upon upgrading to SQL Server 2012 or newer. Using HttpWebRequest works with an "approved" library that is guaranteed to always works across upgrades of the .NET Framework.
There are numerous questions already on here regarding these issues. I will try to find some and update this with a few of them.
Also, just FYI, the output shown in the question, which appears to be the results of executing: SELECT * FROM sys.dm_clr_properties;. Please be aware that the "version" shown, while often referred to as the Framework version, is actually just the CLR version, and those two things are not the same thing.

Assembly dependency in SQL Server 2008

When I register the assembly System.ServiceModel.dll I get this warning message:
After that I am trying to register Microsoft.Transactions.Bridge.dll and get this warning:
What directory / folder are you trying to pull in those DLLs from? You should only need to create the ServiceModel Assembly. This will require that the Database be set to TRUSTWORTHY ON and that you create the Assembly as UNSAFE.
That being said, you would be better off finding an entirely different approach given that very limited nature of what you are building. SQLCLR is a very restricted environment and does not allow for mixed-mode Assemblies; only pure MSIL Assemblies are allowed. In .NET Framework versions 2.0, 3.0, and 3.5, the ServiceModel library was pure MSIL so importing it did work. However, starting with .NET Framework v 4.0, ServiceModel changed to be a mixed-mode DLL and hence cannot be imported into SQL Server starting with SQL Server 2012 (i.e. the first version of SQL Server to be linked to CLR v 4.0 which uses .NET Framework versions 4.0 through the current 4.7 (I think)). And there is no fix outside of re-writing the code to no longer reference ServiceModel. Please see my answer here for more details on that:
(Unfixable) Assembly exists on SQL Server 2014 but it claims it doesn't have it

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?
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).

Deploying an WPF application with Crystal Reports and SQL Server

I have completed a WPF application in Visual Studio 2010 and SQL Server 2008 Express. I have also used Crystal Reports in my project. Now I need to deploy the application on client's systems. I assume that I will have to install the following pre-requisites first.
.Net Framework 4.0
MS SQL Server 2008 express (which may require .Net 2.0)
CR Runtime for .Net 4.0
Report Viewer
IS there a way so that everything installs on its own? I have tried selecting all the above as ** prerequisites**, but that gives me an error that CR Runtime msi not found. Can I also include all the files within my software in the bin folder?
Please give me suggestions.
you can download CRRuntime_32bit_13_0_1.msi from SAP website (google it) and place it in this location:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\Crystal Reports
for .NET Framework 4.0\

Resources