| title | Implementing Assemblies | Microsoft Docs | |
|---|---|---|
| ms.custom | ||
| ms.date | 03/16/2017 | |
| ms.prod | sql | |
| ms.reviewer | ||
| ms.technology | clr | |
| ms.topic | reference | |
| helpviewer_keywords |
|
|
| ms.assetid | c228d7bf-a906-4f37-a057-5d464d962ff8 | |
| author | rothja | |
| ms.author | jroth |
[!INCLUDEappliesto-ss-xxxx-xxxx-xxx-md] This topic provides information about the following areas to help you implement and work with assemblies in the database:
-
Creating assemblies
-
Modifying assemblies
-
Dropping, disabling, and enabling assemblies
-
Managing assembly versions
Assemblies are created in [!INCLUDEssNoVersion] by using the [!INCLUDEtsql] CREATE ASSEMBLY statement, or in the [!INCLUDEssManStudioFull] by using the Assembly Assisted Editor. Additionally, deploying a SQL Server Project in [!INCLUDEmsCoName] [!INCLUDEvsprvs] registers an assembly in the database that was specified for the project. For more information, see Deploying CLR Database Objects.
To create an assembly by using Transact-SQL
To create an assembly by using SQL Server Management Studio
Assemblies are modified in [!INCLUDEssNoVersion] by using the [!INCLUDEtsql] ALTER ASSEMBLY statement or in [!INCLUDEssManStudioFull] by using the Assembly Assisted Editor. You can modify an assembly when you want to do the following:
-
Change the implementation of the assembly by uploading a newer version of the binaries of the assembly. For more information, see Managing Assembly Versions later in this topic.
-
Change the permission set of the assembly. For more information, see Designing Assemblies.
-
Change the visibility of the assembly. Visible assemblies are available for referencing in [!INCLUDEssNoVersion]. Nonvisible assemblies are not available, even if they have been uploaded in the database. By default, assemblies uploaded to an instance of [!INCLUDEssNoVersion] are visible.
-
Add or drop a debug or source file associated with the assembly.
To modify an assembly by using Transact-SQL
To modify an assembly by using SQL Server Management Studio
Assemblies are dropped by using the [!INCLUDEtsql] DROP ASSEMBLY statement or [!INCLUDEssManStudioFull].
To drop an assembly by using Transact-SQL
To drop an assembly by using SQL Server Management Studio
By default, all assemblies that are created in [!INCLUDEssNoVersion] are disabled from executing. You can use the clr enabled option of the sp_configure system stored procedure to disable or enable the execution of all assemblies that are uploaded in [!INCLUDEssNoVersion]. Disabling assembly execution prevents common language runtime (CLR) functions, stored procedures, triggers, aggregates, and user-defined types from executing, and stops those that are currently executing. Disabling assembly execution does not disable the ability to create, alter, or drop assemblies. For more information, see clr enabled Server Configuration Option.
To disable and enable assembly execution
When an assembly is uploaded to an instance [!INCLUDEssNoVersion], the assembly is stored and managed within the database system catalogs. Any changes made to the definition of the assembly in the [!INCLUDEmsCoName] [!INCLUDEdnprdnshort] should be propagated to the assembly that is stored in the database catalog.
When you have to modify an assembly, you must issue an ALTER ASSEMBLY statement to update the assembly in the database. This will update the assembly to the latest copy of [!INCLUDEdnprdnshort] modules holding its implementation.
The WITH UNCHECKED DATA clause of the ALTER ASSEMBLY statement instructs [!INCLUDEssNoVersion] to refresh even those assemblies upon which persisted data in the database is dependent. Specifically, you must specify WITH UNCHECKED DATA if any of the following exist:
-
Persisted computed columns that reference methods in the assembly, either directly, or indirectly, through [!INCLUDEtsql] functions or methods.
-
Columns of a CLR user-defined type that depend on the assembly, and the type implements a UserDefined (non-Native) serialization format.
Caution
If WITH UNCHECKED DATA is not specified, [!INCLUDEssNoVersion] tries to prevent ALTER ASSEMBLY from executing if the new assembly version affects existing data in tables, indexes, or other persistent sites. However, [!INCLUDEssNoVersion] does not guarantee that computed columns, indexes, indexed views, or expressions will be consistent with the underlying routines and types when the CLR assembly is updated. Be careful when you execute ALTER ASSEMBLY to make sure that there is no mismatch between the result of an expression and a value that is based on that expression stored in the assembly.
Only members of the db_owner and db_ddlowner fixed database role can execute run ALTER ASSEMBLY by using the WITH UNCHECKED DATA clause.
[!INCLUDEssNoVersion] posts a message to the Windows application event log that the assembly has been modified with unchecked data in the tables. [!INCLUDEssNoVersion] then marks any tables that contain data dependent on the assembly as having unchecked data. The has_unchecked_assembly_data column of the sys.tables catalog view contains the value 1 for tables that contain unchecked data, and 0 for tables without unchecked data.
To resolve the integrity of unchecked data, run DBCC CHECKDB WITH EXTENDED_LOGICAL_CHECKS against each table that has unchecked data. If DBCC CHECKDB WITH EXTENDED_LOGICAL_CHECKS fails, you must either delete the table rows that are not valid or modify the assembly code to address problems, and then issue additional ALTER ASSEMBLY statements.
ALTER ASSEMBLY changes the assembly version. The culture and public key token of the assembly remain the same.SQL Server does not allow registering different versions of an assembly with the same name, culture and public key.
If references to assemblies stored in [!INCLUDEssNoVersion] are redirected to specific versions by using publisher policy or computer-wide administrator policy, you must do either of the following:
-
Make sure the new version to which this redirection is made is in the database.
-
Modify any statements to the external policy files of the computer or publisher policy to make sure that they reference the specific version that is in the database.
Otherwise, an attempt to load a new assembly version to the instance of [!INCLUDEssNoVersion] will fail.
To update the version of an assembly
Assemblies (Database Engine)
Getting Information About Assemblies