I'm trying to pass in a parameter from my application to do a search inside a stored procedure. I pass in the parameter like this:
SqlParameter param1 = new SqlParameter(@"@FilterCustomerPO", "G06756");
param1.DbType = DbType.AnsiString;
param1.Direction = ParameterDirection.Input;
param1.Size = 50;
sqlCmd.Parameters.Add(param1);
In the stored procedure, it is defined like this:
ALTER PROCEDURE [dbo].[usp_POListing]
@FilterCustomerPO VARCHAR (50)
AS
BEGIN
SELECT *
FROM [Order]
WHERE PONumber = @FilterCustomerPO
END
The PONumber
column is encrypted using DETERMINISTIC
encryption type.
When I pass in a value, I get an error:
Operand type clash: varchar is incompatible with varchar(50) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'ColumnEncryptionKey', column_encryption_key_database_name = 'DataPortal') collation_name = 'SQL_Latin1_General_CP1_CI_AS'
I've seen a lot of other people reporting on this, but none of those solutions worked for me. I'm using parameterized queries, as you can see, so not sure what I could be missing.
EDIT:
I've also tried passing in the parameter this way - same error:
sqlCmd.Parameters.Add("FilterCustomerPO", SqlDbType.VarChar, 50);
sqlCmd.Parameters["FilterCustomerPO"].Value = "G06756"
The definition of the Order Table is as follows:
CREATE TABLE [dbo].[Order]
(
[OrderID] [INT] IDENTITY(1,1) NOT NULL,
[CustomerID] [INT] NOT NULL,
[OrderNumber] [INT] NOT NULL,
[DBCOrderNumber] [VARCHAR](25) NOT NULL,
[PONumber] [VARCHAR](50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [ColumnEncryptionKey], ENCRYPTION_TYPE = Deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NOT NULL,
[BillingName] [VARCHAR](255) NOT NULL,
CONSTRAINT [PK_Order]
PRIMARY KEY CLUSTERED ([OrderID] ASC)
WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
My client connection string also includes the Column Encryption Setting=Enabled
Please note: I am able to retrieve data just fine. It's when I send parameters into the query, and try to do a comparison/filter when I get the error.