Hi Mona,
Apologies for the late response. I had to multiple tests to identify the exact scenario giving this error.
I checked all the columns in my table and did confirm that there are no columns with nvarchar(4000). Not sure where is it coming from.
To test it further to know if this is an issue with nvarchar columns only, I created a test table and run my package against that. I am able to reproduce the issue and identify the scenario of this error now. However, still clueless on why is it behaving so and what is the fix.
Here is the schema of my tables.
CREATE TABLE [dbo].[source_flat](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](1000) NULL,
[address] [nvarchar](256) NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Destination table:
CREATE TABLE [dbo].[destn_flat](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](1000) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [QC_AE_CEK_1], ENCRYPTION_TYPE = Deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NULL,
[address] [nvarchar](256) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [QC_AE_CEK_1], ENCRYPTION_TYPE = Deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Note that the destination is encrypted.
Data in source:
Note that the first row has an empty string for the address and this is what gives the error.
If I update the address column of the first row to a string value, the package goes through fine.
I also tried these queries in the source selection, but I am still getting the same error.
Here is the error:
[ADO NET Destination [2]] Error: An exception has occurred during data insertion, the message returned from the provider is: Operand type clash: **nvarchar(4000)** encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'QC_AE_CEK_1', column_encryption_key_database_name = 'MyDB') is incompatible with **nvarchar(256)** encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'QC_AE_CEK_1', column_encryption_key_database_name = 'MyDB')
Statement(s) could not be prepared.
Now we know the scenario:
When loading data with identity insert ON to an Always Encrypted destination table using ADO.NET connection, and if the source column has an empty string for an encrypted column, then SSIS throws the error nvarchar(4000) does not match with nvarchar(column size in destination table). Why is it behaving so and what is the fix for this?