I have the following scenario where I have to update 2 always encrypted columns in a SQL Server stored procedure.
- One column is in the current database (insert statement)
- The other column is in another database which is being accessed by a synonym (update statement)
The always encrypted columns' master key is in Azure Keyvault.
The stored procedure is compiling successfully with either insert or the update, but not both.
When I include both the statements in the stored procedure, it fails with the error message:
Encryption scheme mismatch for columns/variables '@variableName'. The encryption scheme for the columns/variables is (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEKName', column_encryption_key_database_name = 'DBName') and the expression near line '8' expects it to be DETERMINISTIC, or PLAINTEXT.
Stored procedure code:
ALTER PROCEDURE [dbo].[UserCreatedSPName]
AS
BEGIN
INSERT INTO Table(columns list)
VALUES (incoming params)
UPDATE SynonymTable
SET AlwaysEncryptedColumn = [@sameincomingvariable as in above insert]
WHERE [filter condition]
END
Is this something that can be accomplished?
I have tried moving the update statement into a separate stored procedure and calling it from the main stored procedure - but I am still getting the same error.
Update: The Insert and Update are both happening the same Stored procedure. Also the 2 tables have a separate Column Master Keys in Azure key vault