SqlConnection.ColumnEncryptionQueryMetadataCacheEnabled 屬性


取得或設定值,指出是否要針對根據已啟用 Always Encrypted 的資料庫執行的參數化查詢,啟用 (true) 或停用 (false) 查詢中繼資料快取。Gets or sets a value that indicates whether query metadata caching is enabled (true) or not (false) for parameterized queries running against Always Encrypted enabled databases. 預設值為 true。The default value is true.

 static property bool ColumnEncryptionQueryMetadataCacheEnabled { bool get(); void set(bool value); };
public static bool ColumnEncryptionQueryMetadataCacheEnabled { get; set; }
member this.ColumnEncryptionQueryMetadataCacheEnabled : bool with get, set
Public Shared Property ColumnEncryptionQueryMetadataCacheEnabled As Boolean



如果已啟用查詢中繼資料快取,即會傳回 true;否則為 false。Returns true if query metadata caching is enabled; otherwise false. true 為預設值。true is the default.


針對參數化查詢,SqlClient 會對參數中繼資料進行 SQL Server 的往返,以查看需要加密的參數,以及) 使用哪些金鑰和演算法 (。For parameterized queries, SqlClient makes a roundtrip to SQL Server for parameter metadata, to see which parameter it needs to encrypt and how (which keys and algorithms should be used). 如果應用程式多次呼叫相同的查詢,則每次都會對伺服器進行額外的往返,進而降低應用程式效能。If the application calls the same query multiple times, an extra roundtrip is made to the server each time, which degrades application performance.

>sqlconnection.columnencryptionquerymetadatacacheenabled 設定為 true 時,如果多次呼叫相同的查詢,伺服器的往返將只會進行一次。With ColumnEncryptionQueryMetadataCacheEnabled set to true, if the same query is called multiple times, the roundtrip to the server will be made only once. 快取具有不可設定的最大大小參數,其設定為2000查詢。The cache has a non-configurable Max size parameter that is set to 2000 queries.