Operand type clash: varchar is incompatible with varchar(50) trying to insert in encrypted database

后端 未结 3 884
有刺的猬
有刺的猬 2020-12-10 08:30

I am getting a SqlException:

Operand type clash: varchar is incompatible with varchar(50) encrypted with (encryption_type = \'DETERMINI

相关标签:
3条回答
  • 2020-12-10 08:54

    If someone is still looking for an answer on this, what worked for me is that you need to use DbType.AnsiStringFixedLength data type in the SqlParameter data type, for the encrypted columns.

    Refer this article for more information

    0 讨论(0)
  • 2020-12-10 09:06

    Anyone who still face this issue and none of the above checks didn't help, make sure the parameter names exactly match (case sensitively) both in the procedure and the code.

    0 讨论(0)
  • 2020-12-10 09:07

    There are 2 things you can try,

    Ensure that Column encryption setting is enabled in your connection string. This can be done using a SqlConnectionStringBuilder object and setting SqlConnectionStringBuilder.ColumnEncryptionSetting to Enabled as follows

    strbldr.ColumnEncryptionSetting = SqlConnectionColumnEncryptionSetting.Enabled;
    

    If your stored procedure was created before you encrypted your column, you will need to refresh metadata for your stored procedure as follows

    Use [Database]
    GO    
    --Do this for all stored procedures
    EXEC sys.sp_refresh_parameter_encryption @name = '[dbo].[Clients_Insert]'
    
    0 讨论(0)
提交回复
热议问题