如何在 SQL CLR 项目中添加 c# class library/ class dll?

How do I add c# class library/ class dll in SQL CLR project?

如何在 SQL CLR 项目中添加 c# class library/ class dll?。

我添加了 class 库 dll/ class dll 但在程序集创建期间 SQL 服务器 2012 出现错误

Assembly references assembly 'system.runtime.serialization, version=4.0.0.0, culture=neutral, 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(The system cannot find the file specified.)). Please load the referenced assembly into the current database and retry your request.

您必须先注册不受支持的库才能使用它们。

-- You will have to use the Runtime Serialization from .NET v3

ALTER DATABASE [<<Database Name>>] SET TRUSTWORTHY ON;
CREATE ASSEMBLY AnyName_You_Want
FROM 
--'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Runtime.Serialization.dll'
'C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\System.Runtime.Serialization.dll'
WITH PERMISSION_SET = UNSAFE;

摘录:

Unsupported libraries can still be called from your managed stored procedures, triggers, user-defined functions, user-defined types, and user-defined aggregates. The unsupported library must first be registered in the SQL Server database, using the CREATE ASSEMBLY statement, before it can be used in your code. Any unsupported library that is registered and run on the server should be reviewed and tested for security and reliability.

For example, the System.DirectoryServices namespace is not supported. You must register the System.DirectoryServices.dll assembly with UNSAFE permissions before you can call it from your code. The UNSAFE permission is necessary because classes in the System.DirectoryServices namespace do not meet the requirements for SAFE or EXTERNAL_ACCESS. For more information, see CLR Integration Programming Model Restrictions and CLR Integration Code Access Security.

CLR integration in SQL Server 仅支持 .NET Framework 库的一个子集。 SQL 服务器中 CLR 集成支持的 libraries/namespaces 是:

  • 自定义编组器
  • Microsoft.VisualBasic
  • Microsoft.VisualC
  • mscorlib
  • 系统
  • System.Configuration
  • System.Data
  • System.Data.OracleClient
  • System.Data.SqlXml
  • System.Deployment
  • System.Security
  • System.Transactions
  • System.Web.Services
  • System.Xml
  • System.Core.dll
  • System.Xml.Linq.dll