Ócáid
Mar 31, 11 PM - Apr 2, 11 PM
An ócáid foghlama SQL, Fabric and Power BI is mó. Márta 31 – 2 Aibreán. Bain úsáid as cód FABINSIDER chun $ 400 a shábháil.
Cláraigh inniuNí thacaítear leis an mbrabhsálaí seo a thuilleadh.
Uasghrádú go Microsoft Edge chun leas a bhaint as na gnéithe is déanaí, nuashonruithe slándála, agus tacaíocht theicniúil.
Applies to:
SQL Server 2016 (13.x) and later versions
You can create a database object inside an instance of SQL Server that is programmed in an assembly created in the .NET Framework common language runtime (CLR). Database objects that can use the rich programming model provided by the common language runtime include aggregate functions, functions, stored procedures, triggers, and types.
Creating a CLR function in SQL Server involves the following steps:
Define the function as a static method of a class in a language supported by the .NET Framework. For more information about how to program functions in the common language runtime, see CLR user-defined functions. Then, compile the class to build an assembly in the .NET Framework by using the appropriate language compiler.
Register the assembly in SQL Server by using the CREATE ASSEMBLY
statement. For more information about assemblies in SQL Server, see Assemblies (Database Engine).
Create the function that references the registered assembly by using the CREATE FUNCTION statement.
Executing CLR code is off by default in SQL Server. You can create, alter, and drop database objects that reference managed code modules, but these references don't execute in SQL Server, unless the clr enabled server configuration option is enabled by using sp_configure.
Deploying a SQL Server Project in Visual Studio registers an assembly in the database that was specified for the project. Deploying the project also creates CLR functions in the database for all methods annotated with the SqlFunction
attribute. For more information, see Deploy CLR database objects.
You can use CLR functions to access external resources such as files, network resources, web services, and other databases (including remote instances of SQL Server). CLR functions can use various classes in .NET Framework, such as System.IO
, System.WebServices
, System.Sql
, and so on. The assembly that contains such functions should at least be configured with the EXTERNAL_ACCESS
permission set for this purpose. For more information, see CREATE ASSEMBLY.
The SQL Client Managed Provider can be used to access remote instances of SQL Server. However, loopback connections to the originating server aren't supported in CLR functions.
CLR functions can access native (unmanaged) code, such as code written in C or C++, via the use of PInvoke
from managed code (see Calling Native Functions from Managed Code for details). You can reuse legacy code as CLR UDFs, or write performance-critical UDFs in native code, and requires using an UNSAFE
assembly. See CLR integration Code Access Security for cautions about use of UNSAFE
assemblies.
Ócáid
Mar 31, 11 PM - Apr 2, 11 PM
An ócáid foghlama SQL, Fabric and Power BI is mó. Márta 31 – 2 Aibreán. Bain úsáid as cód FABINSIDER chun $ 400 a shábháil.
Cláraigh inniuOiliúint
Modúl
Create stored procedures and user-defined functions - Training
This content is a part of Create stored procedures and user-defined functions.
Doiciméadúchán
CLR Table-Valued Functions - SQL Server
A table-valued function returns a table. In SQL Server CLR integration, you can write table-valued functions in managed code.
CLR Scalar-Valued Functions - SQL Server
A scalar-valued function returns a single value. In SQL Server CLR integration, you can write scalar-valued user-defined functions in managed code.
Get Started With CLR Integration - SQL Server
This article describes the namespaces and libraries required to compile database objects using the Microsoft SQL Server integration with the .NET Framework CLR.