Relational Database ServiceRelational Database Service

Elastic Cloud Server
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
Domain Name Service
VPC Endpoint
Cloud Connect
Enterprise Switch
Security & Compliance
Web Application Firewall
Host Security Service
Data Encryption Workshop
Database Security Service
Advanced Anti-DDoS
Data Security Center
Container Guard Service
Situation Awareness
Managed Threat Detection
Cloud Certificate Manager
Anti-DDoS Service
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GaussDB(for MySQL)
Distributed Database Middleware
GaussDB(for openGauss)
Developer Services
Distributed Cache Service
Simple Message Notification
Application Performance Management
Application Operations Management
Blockchain Service
API Gateway
Cloud Performance Test Service
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Cloud Communications
Message & SMS
Cloud Ecosystem
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP License Service
Support Plans
Customer Operation Capabilities
Partner Support Plans
Professional Services
Intelligent EdgeFabric
SDK Developer Guide
API Request Signing Guide
Koo Command Line Interface
Updated at: Apr 02, 2022 GMT+08:00

CLR Integration


The common language runtime (CLR) is the core of Microsoft .NET Framework and provides the execution environment for all .NET Framework code. Code that runs within the CLR is referred to as managed code. The CLR provides various functions and services required for program execution, including just-in-time (JIT) compilation, allocating and managing memory, enforcing type safety, exception handling, thread management, and security.

SQL CLR is a new function of SQL Server 2005. It injects the CLR service of .NET Framework into SQL Server, so that some database objects of SQL Server can be developed using the .NET Framework programming language (currently, only VB.NET and C# are supported). These database objects include stored procedures, triggers, user-defined functions, user-defined types, and user-defined aggregates. To execute the CLR code, you need to enable CLR integration first.

For more information about CLR integration, see Common Language Runtime (CLR) Integration Programming Concepts.

For more information about CLR integration security, see CLR Integration Security.


RDS for SQL Server can deploy SAFE assemblies only.

Enabling CLR

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click in the upper left corner of the page and choose Database > Relational Database Service. The RDS console is displayed.
  4. On the Instance Management page, click the target DB instance.
  5. In the navigation pane on the left, choose Parameters. On the displayed page, enter clr enabled and clr strict security in the search box in the upper right corner.

    • clr enabled determines whether the CLR integration is enabled.
    • clr strict security is a specific parameter to SQL Server 2017. This parameter explains the SAFE, EXTERNAL ACCESS, and UNSAFE permissions of SQL Server. The value 1 causes the DB engine to ignore the PERMISSION_SET information on the assemblies, and always interprets them as UNSAFE. For more information, see CLR strict security at the Microsoft site.

  6. Set the clr enabled value.

    Set clr enabled to 1 and click Save. In the displayed dialog box, click Yes to enable the CLR function.

    • clr enabled: The value 1 indicates that the CLR function is enabled. The value 0 indicates that the CLR function is disabled. Only clr enabled needs to be set to enable the CLR function.
    • clr strict security: The default value is 1 and no configuration is required.

  7. On the Change History tab, check that the value of clr enabled has been changed to 1.

Creating a SAFE CLR Assembly

The following factors should be considered when you design assemblies:

  • Packaging assemblies
  • Management assembly security
  • Restrictions on assemblies

For more information, see Designing Assemblies.

Example: Creating a C# CLR Assembly

Microsoft SQL Server provides assemblies to make database operations simple and convenient.

When you restore data to a new or an existing DB instance, the clr enabled parameter is disabled by default. To use the CLR integration function, you need to enable clr enabled first.


  1. Create a C# function to compile an SQL Server DLL.

    Figure 1 C# function code

    For more information about user-defined functions, see CLR User-Defined Functions.

  2. Use SQL Server Management Studio to connect to the database.

    Figure 2 Connecting to the server

  3. Select the target database and create the corresponding assembly.

    • Only the SAFE assembly (Permission set is Safe) can be created.
    • The DLL file is saved in the hexadecimal format, as shown in Figure 4.
    Figure 3 Creating an assembly
    Figure 4 DLL file

  4. Execute the program. If the execution result is shown as Figure 5, the execution is successful. The TESTS assembly is added, as shown in Figure 6.

    Figure 5 Execution result
    Figure 6 TESTS assembly

Did you find this page helpful?

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?

Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel