Deploying SQL CLR Project fails when creating assembly on database

不羁的心 提交于 2019-12-04 19:15:29

First off, only a short list of .NET Framework libraries are "supported". You can find that list on the MSDN page for Supported .NET Framework Libraries. System.Data.DataSetExtensions is not one of them. That is why you got the first error.

The second thing posted is a warning, not an error. It is telling you that you can run into one or more problems that Microsoft will not care about or fix as you are doing something that is unsupported.

Run the following in the database where you are deploying the assemblies:

SELECT * FROM sys.assemblies sa WHERE sa.is_user_defined = 1;

and you should see both. Although if System.Data.DataSetExtensions has dependent libraries, they won't be automatically loaded because only the folder that the initial CREATE ASSEMBLY is pointing to will get loaded, and that is now where your DLL is being built and not the .NET Framework folder.

You might be better off loading System.Data.DataSetExtensions by itself in its own CREATE ASSEMBLY pointing to the appropriate C:\Windows\Microsoft.NET\Framework (or Framework64) folder. Especially if you notice that the error message shows "Code size is zero", which I have only seen when trying to load the DLL from one of the Reference Assemblies folders.

Now, because this is an unsupported library it probably does stuff that disallow it from being loaded as SAFE. Since we don't have the private key info in order to go the ideal route of creating an Asymmetric Key and then a Login based on that Asymmetric Key, you have little choice but to:

  • set the database you are deploying to as TRUSTWORTHY via:

    ALTER DATABASE [DatabaseName] SET TRUSTWORTHY ON;
    
  • load the assembly WITH PERMISSION_SET = UNSAFE

Essentially:

USE [DatabaseName];

ALTER DATABASE CURRENT SET TRUSTWORTHY ON;

CREATE ASSEMBLY [System.Data.DataSetExtensions]
FROM
   'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Data.DataSetExtensions.dll'
WITH PERMISSION_SET = UNSAFE;

After that you should be able to load your assembly, though it will likely have to be set to UNSAFE as well.

And I would delete the copy of System.Data.DataSetExtensions.dll that you put in your build folder.


For more info on SQLCLR in general, please see the series I am writing on SQL Server Central: Stairway to SQLCLR (free registration required).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!