无法将 varchar empty/null 值插入或更新到始终加密的列中

Cannot insert or update varchar empty/null value into always encrypted column

我正在尝试使用 sql 客户端将 C# 中的空 ""null 值更新为始终加密的列;但是我遇到了以下错误。如果我传递 space " ".

它会起作用

错误:

nvarchar(4000) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEK', column_encryption_key_database_name = 'db') is incompatible with nvarchar(50) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEK', column_encryption_key_database_name = 'db')

工作代码如下:

        SqlConnection connection = new SqlConnection(dbString);
        connection.Open();
        SqlParameter p = new SqlParameter("@lastname", System.Data.SqlDbType.NVarChar, 50);
        p.Value = string.Empty;

        SqlCommand command = new SqlCommand("update associate set lastname=@lastname", connection);
        command.Parameters.Add(p);
        command.ExecuteNonQuery();
        connection.Close();

问题是客户端参数定义必须与服务器上的加密列类型完全匹配。