问题
How do I add c# class library/ class dll in SQL CLR project ?.
I add the class library dll/ class dll but got error in SQL server 2012 during assembly creation
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.
回答1:
You have to register unsupported libraries before you can use them.
-- 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;
Excerpt:
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 only supports a subset of .NET Framework Libraries. The libraries/namespaces supported by CLR integration in SQL Server are:
- CustomMarshalers
- Microsoft.VisualBasic
- Microsoft.VisualC
- mscorlib
- System
- 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
来源:https://stackoverflow.com/questions/30126528/how-do-i-add-c-sharp-class-library-class-dll-in-sql-clr-project