Installation
Requirements
- SQL Server 2012 or later (2017+ recommended; note the CLR strict security changes it introduced). CLR integration is included in every edition, including Express.
- .NET Framework SDK / Visual Studio with the SQL Server Data Tools
(SSDT) workload, or the
Microsoft.SqlServer.Serverreference for plain class libraries. - Permission to run
sp_configureandCREATE ASSEMBLYon the target instance (ALTER SETTINGSandCREATE ASSEMBLYpermissions, typically sysadmin in development).
Enable CLR on the instance
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'clr enabled', 1;
RECONFIGURE;
Verify:
SELECT name, value_in_use
FROM sys.configurations
WHERE name IN ('clr enabled', 'clr strict security');
Project setup
Option A — SSDT database project (recommended)
- Create a SQL Server Database Project in Visual Studio.
- Add a SQLCLR item (function, stored procedure, aggregate, or type).
- Set the target platform to match your SQL Server version.
- Publish — SSDT generates the
CREATE ASSEMBLYand wrapper DDL for you.
Option B — plain class library
- Create a .NET Framework class library (match the CLR version your SQL Server hosts — CLR 4 for SQL Server 2012+).
- Reference
System.Dataand use theMicrosoft.SqlServer.Servernamespace attributes. - Deploy by hand with
CREATE ASSEMBLYas shown in the Quick Start.
note
SQL Server hosts the .NET Framework runtime. Assemblies targeting .NET Core / .NET 5+ cannot be loaded by CLR integration.
Verify the install
SELECT * FROM sys.assemblies WHERE is_user_defined = 1;
SELECT * FROM sys.assembly_modules;
If your assembly and its modules appear, you're ready for the Examples.