newtonsoft.json parser in a C# CLR for SQL Server

2020-07-18 04:23发布

问题:

I have created a CLR which uses the newtonsoft json parser.

I need to deploy the CLR. I have created an assembly for the parser dependency:

CREATE ASSEMBLY [Newtonsoft.Json] FROM 'C:\share\Release\Newtonsoft.Json.dll' WITH PERMISSION_SET = UNSAFE

The above statement throws an error:

`Assembly 'Newtonsoft.Json' references assembly 'system.runtime.serialization, version=3.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089.', which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: 2(failed to retrieve text for this error. Reason: 15105)).` Please load the referenced assembly into the current database and retry your request.

I am using version 7.xx of the parser. I am targeting .NET 3.5

What is the proper procedure for deploying the CLR to sql server 2008 r2?

回答1:

Sorry, I had made an incorrect assumption in my comment. Only certain libraries in the GAC are supported for SQL CLR by default.

In order to use that library, you'll need to explicitly add it as well.

CREATE ASSEMBLY System_Runtime_Serialization FROM 'C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\System.Runtime.Serialization.dll'
WITH PERMISSION_SET = UNSAFE
GO

If you are using 64-bit SQL Server, make sure you use Framework64 instead of Framework.