简体   繁体   English

SQL Server始终加密的操作数类型冲突:运行EXEC sproc时,varchar与varchar(60)不兼容

[英]SQL Server Always Encrypted Operand type clash: varchar is incompatible with varchar(60) when running EXEC sproc

I am unable to EXEC a stored procedure that upserts a table that has an encrypted column using Always Encrypted. 我无法执行存储过程,该存储过程使用Always Encrypted向上插入具有加密列的表。 However, I am able to copy the SQL from the sproc and run that as regular SQL with the parameters set, Just cannot get the sproc to fire when executing the sproc via the EXEC function in SSMS which is also causing problems in the application 但是,我能够从sproc复制SQL并使用设置了参数的普通SQL运行它, 只是无法通过SSMS中的EXEC函数执行sproc时触发sproc,这也会导致应用程序出现问题

The table has a trigger on it that inserts into another audit table of similar structure that is also encrypted using the same encryption. 该表上有一个触发器,该触发器可插入另一个具有类似结构的审计表中,该审计表也使用相同的加密方法进行了加密。 I have done the usual thing: 我做了平常的事情:

  • Checking the Enable Parameterizaion for Always Encrypted in Query Options 检查查询选项中始终加密的启用参数化
  • Setting column encryption setting=enabled on the Connection Settings. 在连接设置上设置列加密设置为启用。
  • Refreshing the encyrption metadata for the sproc: 刷新存储过程的加密元数据:

      EXEC sp_refresh_parameter_encryption 'organization.uspOrganizationAddressUpsert' 

    Tables: 表:

      CREATE TABLE [organization].[OrganizationAddress]( [OrganizationAddressId] [int] IDENTITY(1,1) NOT NULL, [CreatedUser] [int] NOT NULL, [CreatedDate] [datetime2](7) NOT NULL, [LastUpdateUser] [int] NOT NULL, [LastUpdateDate] [datetime2](7) NOT NULL, [RemovedDate] [datetime2](7) NULL, [Address1] [varchar](60) NOT NULL, [Address2] [varchar](60) NULL, [City] [varchar](60) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [CEK_Auto1], ENCRYPTION_TYPE = Deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NOT NULL, [State] [varchar](60) NOT NULL, [ZipCode] [varchar](60) NOT NULL, [ClientNumberId] [int] NOT NULL CREATE TABLE [audit].[OrganizationAddressAudit]( [OrganizationAddressId] [int] NOT NULL, [CreatedUser] [int] NOT NULL, [CreatedDate] [datetime2](7) NOT NULL, [LastUpdateUser] [int] NOT NULL, [LastUpdateDate] [datetime2](7) NOT NULL, [RemovedDate] [datetime2](7) NULL, [Address1] [varchar](60) NOT NULL, [Address2] [varchar](60) NULL, [City] [varchar](60) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [CEK_Auto1], ENCRYPTION_TYPE = Deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NOT NULL, [State] [varchar](60) NOT NULL, [ZipCode] [varchar](60) NOT NULL, [ClientNumberId] [int] NOT NULL, [OperationDate] [datetime] NOT NULL, [Operation] [varchar](50) NOT NULL, [OperationBy] [varchar](100) NOT NULL 

    Stored Procedure: 存储过程:

      ALTER PROCEDURE [organization].[uspOrganizationAddressUpsert] @OrganizationId INT, @ExecutingUserId INT, @Address1 VARCHAR(60), @Address2 VARCHAR(60), @City VARCHAR(60), @State VARCHAR(60), @ZipCode VARCHAR(60), @ClientNumberId INT AS BEGIN SET NOCOUNT ON DECLARE @RightNow AS DATETIME2 = SYSDATETIME() If EXISTS (Select 1 From [organization].[OrganizationAddress] Where ClientNumberId = @ClientNumberId) BEGIN UPDATE [organization].[OrganizationAddress] SET LastUpdateUser = @ExecutingUserId, LastUpdateDate = @RightNow, Address1 = @Address1, Address2 = @Address2, City = @City, [State] = @State, ZipCode = @ZipCode, RemovedDate = Null Where ClientNumberId = @ClientNumberId END ELSE BEGIN -- INSERT part of the UPSERT INSERT INTO [organization].[OrganizationAddress] (CreatedUser ,CreatedDate ,LastUpdateUser ,LastUpdateDate ,Address1 ,Address2 ,City ,[State] ,ZipCode ,ClientNumberId) VALUES (@ExecutingUserId ,@RightNow ,@ExecutingUserId ,@RightNow ,@Address1 ,@Address2 ,@City ,@State ,@ZipCode ,@ClientNumberId) END END 

    Running the stored procedure code with the paramteers set is fine, but I am unable to EXEC the sproc: 使用参数集运行存储过程代码很好,但是我无法执行该存储过程:

      declare @orgId INT = 1; declare @client int = 888; declare @user int = 1; declare @Add1 varchar(60)= 'Test Address1'; declare @Add2 varchar(60)= 'Test Address2'; declare @city varchar(60) = 'City'; declare @state varchar(60) = 'St'; declare @zip varchar(60) = '12345'; EXEC organization.uspOrganizationAddressUpsert @OrganizationID=@orgID, @ExecutingUserId = @user, -- int @Address1 = @Add1, -- varchar(60) @Address2 = @Add2, -- varchar(60) @City = @city, -- varchar(60) @State = @state, -- varchar(60) @ZipCode = @zip, -- varchar(60) @ClientNumberId = @client; -- int Msg 206, Level 16, State 2, Procedure uspOrganizationAddressUpsert, Line 0 [Batch Start Line 1] Operand type clash: varchar is incompatible with varchar(60) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEK_Auto1', column_encryption_key_database_name = 'BankruptcyApp') collation_name = 'SQL_Latin1_General_CP1_CI_AS' 

    I created a similar table in a test DB with VARCHAR(60) for the enrcrypted columns, a trigger, and an audit table and its working fine there and I cant find any differences in the table/sproc/trigger that would allow it to work there and not here. 我在带有VARCHAR(60)的测试数据库中为加密的列,触发器和审计表创建了一个类似的表,并且该表在那里工作良好,我在表/ sproc /触发器中找不到任何可以使它工作的差异那里而不是这里。 I've pretty much exhausted the other posts and blogs I can find. 我已经用尽了我可以找到的其他帖子和博客。

  • Fixed! 固定! Needed to update the app code to specify the data type and length: 需要更新应用代码以指定数据类型和长度:

    parameters.Add("@City", organizationAddress.City, System.Data.DbType.AnsiString, System.Data.ParameterDirection.Input, 60);
    

    where it was previously just: 以前的位置:

    parameters.Add("@City", organizationAddress.City)
    

    This at least get the app to run the sproc but still cant run it from SSMS via EXEC 这至少可以使应用程序运行sproc,但仍然无法通过EXEC从SSMS运行它

    暂无
    暂无

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

    相关问题 SQL Server始终加密:操作数类型冲突:varchar与varchar(max)不兼容 - SQL Server Always Encrypted: Operand type clash: varchar is incompatible with varchar(max) 操作数类型冲突:varchar 与 varchar(255) 使用 Always Encrypted with Secure Enclaves 和 CASE 语句不兼容 - Operand type clash: varchar is incompatible with varchar(255) Using Always Encrypted with Secure Enclaves and CASE statement SQL 服务器错误“操作数类型冲突:varchar 与 int 不兼容” - SQL Server error "Operand type clash: varchar is incompatible with int " 操作数类型冲突:varchar 与尝试插入加密数据库的 varchar(50) 不兼容 - Operand type clash: varchar is incompatible with varchar(50) trying to insert in encrypted database 始终加密的SQL 2016和Entity Framework 6:“操作符类型冲突:datetime2与日期不兼容” - Always Encrypted SQL 2016 and Entity Framework 6: “Operand type clash: datetime2 is incompatible with date” 在 sql 中使用用户定义的表类型时出错 --> 操作数类型冲突:varchar 与“用户定义的表类型”不兼容 - Error while using user-defined table type in sql --> Operand type clash: varchar is incompatible with "user defined table type" 如何修复操作数类型冲突:图像在SQL Server中与varchar(max)不兼容 - How to fix operand type clash : image is incomplate with varchar(max) in sql server SQL 服务器“操作数类型冲突:int 与日期不兼容”错误 - SQL Server 'Operand type clash: int is incompatible with date' error SQL Server-与工会的错误“操作数类型冲突uniqueidentifier与int不兼容” - SQL Server - error 'operand type clash uniqueidentifier is incompatible with int' with Union SQL Server 2012(触发器)操作数类型冲突:int与日期不兼容 - SQL Server 2012 (triggers) Operand type clash: int is incompatible with date
     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM