CLR 已啟用伺服器組態選項clr enabled Server Configuration Option

適用於: 是SQL Server 否Azure SQL Database 否Azure Synapse Analytics (SQL DW) 否平行處理資料倉儲 APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

使用 clr enabled 選項來指定 SQL ServerSQL Server是否能執行使用者組件。Use the clr enabled option to specify whether user assemblies can be run by SQL ServerSQL Server. [CLR 已啟用] 選項提供下列值:The clr enabled option provides the following values:

ReplTest1Value DescriptionDescription
00 SQL ServerSQL Server上不允許組件執行。Assembly execution not allowed on SQL ServerSQL Server.
11 SQL ServerSQL Server上允許組件執行。Assembly execution allowed on SQL ServerSQL Server.

僅限 WOW64。WOW64 only. 請重新啟動 WOW64 伺服器使設定變更生效。Restart WOW64 servers to effect the settings changes. 對於其他伺服器類型,則不需要重新啟動。No restart required for other server types.

當您執行 RECONFIGURE 且 [CLR 已啟用] 選項的執行值從 1 變更為 0 時,會立即卸載包含使用者組件的所有應用程式定義域。When you run RECONFIGURE, and the run value of the clr enabled option is changed from 1 to 0, all application domains containing user assemblies are immediately unloaded.

在輕量型共用下,不支援通用語言執行平台 (CLR) 執行請停用下列兩個選項中的其中一種:"clr enabled" 或 "lightweight pooling"。Common language runtime (CLR) execution is not supported under lightweight pooling Disable one of two options: "clr enabled" or "lightweight pooling". 依賴 CLR 且在 Fiber 模式下無法正常運作的功能包括了 hierarchyid 資料類型、FORMAT 功能、複寫和以原則為基礎的管理。Features that rely upon CLR and that do not work properly in fiber mode include the hierarchyid data type, the FORMAT function, replication, and Policy-Based Management.

警告

CLR 使用 .NET Framework 中的程式碼存取安全性 (CAS),而這不再作為安全性界限受支援。CLR uses Code Access Security (CAS) in the .NET Framework, which is no longer supported as a security boundary. 使用 PERMISSION_SET = SAFE 所建立的 CLR 組件可以存取外部系統資源、呼叫 Unmanaged 程式碼,以及取得系統管理員權限。A CLR assembly created with PERMISSION_SET = SAFE may be able to access external system resources, call unmanaged code, and acquire sysadmin privileges. SQL Server 2017 (14.x)SQL Server 2017 (14.x) 開始,引進稱為 clr strict securitysp_configure 選項,來增強 CLR 組件的安全性。Beginning with SQL Server 2017 (14.x)SQL Server 2017 (14.x), an sp_configure option called clr strict security is introduced to enhance the security of CLR assemblies. clr strict security 會依預設啟用,且將 SAFEEXTERNAL_ACCESS 組件視作已標記為 UNSAFE 一樣。clr strict security is enabled by default, and treats SAFE and EXTERNAL_ACCESS assemblies as if they were marked UNSAFE. 可以基於回溯相容性停用 clr strict security 選項,但不建議這麼做。The clr strict security option can be disabled for backward compatibility, but this is not recommended. Microsoft 建議透過具有已獲授與 master 資料庫中 UNSAFE ASSEMBLY 權限之對應登入的憑證或非對稱金鑰簽署所有組件。Microsoft recommends that all assemblies be signed by a certificate or asymmetric key with a corresponding login that has been granted UNSAFE ASSEMBLY permission in the master database. SQL ServerSQL Server 系統管理員也可以將組件新增至資料庫引擎應該信任的組件清單。administrators can also add assemblies to a list of assemblies, which the Database Engine should trust. 如需詳細資訊,請參閱 sys.sp_add_trusted_assemblyFor more information, see sys.sp_add_trusted_assembly.

範例Example

以下範例會先顯示使用 clr 已啟用選項的目前設定,然後將選項值設定為 1 來啟用選項。The following example first displays the current setting of the clr enabled option and then enables the option by setting the option value to 1. 若要停用此選項,請將值設定為 0。To disable the option, set the value to 0.

EXEC sp_configure 'clr enabled';  
EXEC sp_configure 'clr enabled' , '1';  
RECONFIGURE;    

另請參閱See Also

輕量型共用伺服器組態選項 lightweight pooling Server Configuration Option
伺服器組態選項 (SQL Server) Server Configuration Options (SQL Server)
sp_configure (Transact-SQL) sp_configure (Transact-SQL)
輕量型共用伺服器組態選項lightweight pooling Server Configuration Option