We had to update our server, MS SQL 2019, and encrypt some fields.
Now, in both our application and in MS SQL Managament Studio, it works with a full read of a table (select * from whatever). However, if we add a where-clause it fails.
The general Entity framework queries seem to work, but using SqlQuery. Like:
var personToAddOrUpdate = impro_context.Persone.SqlQuery(
$"select * from persone where signum='{resultedUser.SamAccountName}'").
FirstOrDefault();
This does not work:
Operand type clash: varchar is incompatible with varchar(8000) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'COL_ENCRTY_MASTER_TEST', column_encryption_key_database_name = 'Impro_V2_test') collation_name = 'Estonian_CI_AS'
Also, it does not work in SQL Server management studio
For both, just reading "select * from persone" will work for both
Searching the net and I found e.g. How to query data when columns are encrypted in SQL Server 2016
var personToAddOrUpdate = impro_context.Persone.SqlQuery(
$"DECLARE @MyValue nvarchar(100) = '{resultedUser.SamAccountName}'; \r\n
SELECT Signum FROM persone WHERE Signum = @MyValue).
FirstOrDefault();
Still, this causes:
Encryption scheme mismatch for columns/variables '@MyValue'. The encryption scheme for the columns/variables is (encryption_type = 'PLAINTEXT') and the expression near line '1' expects it to be DETERMINISTIC, or PLAINTEXT.
The query works in SQL Server Management Studio
The page mention DETERMINISTIC, which does also apply to me.
The connection string has the encryption enables, and it actually works for the full reads data correctly, but only queries do now work
data source=eetlsw0115;initial catalog=test;persist security info=True;
user id=something;password=something;multipleactiveresultsets=True;
application name=EntityFramework; Column Encryption Setting = Enabled;