由于加密消息,无法将存储过程添加到数据库

Cannot add a stored procedure to database due to encryption message

我设置了一个本地数据库(SQL Server 2017 Express)。一切正常,但在 SSMS 中创建一个简单的存储过程时出现错误。

例如,这个

CREATE PROCEDURE [dbo].[EMS_Operations_SyncAssetTableByID2]
    @Table_Name VARCHAR(255),
    @Ids_For_Update VARCHAR(255),
    @Is_Test BIT = 0
AS
BEGIN
    DECLARE @DB_String varchar(55) ='Redesign'
END

不会 运行,我收到错误消息:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'PROCEDURE'.

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'PROCEDURE'.

Msg 8180, Level 16, State 1, Procedure sp_describe_parameter_encryption, Line 1 [Batch Start Line 0]
Statement(s) could not be prepared.

Msg 8180, Level 16, State 1, Procedure sp_describe_parameter_encryption, Line 1 [Batch Start Line 0]
Statement(s) could not be prepared.

An error occurred while executing batch. Error message is: Internal error. The format of the resultset returned by sp_describe_parameter_encryption is invalid. One of the resultsets is missing.

我不确定是什么原因造成的,或者数据库是否损坏,因为数据库中有加密,我不确定它在调用什么。

我还注意到批处理中第一个 SQL 语句下方有一条蓝线,上面写着

@DB_String will be converted into a System.Data.SqlClient.SqlParameter with the following properties: SqlDbType = varchar,Size 55, Precision=0

当我 运行 在我们的远程服务器上使用相同的代码时,它可以毫无问题地完成。知道是什么原因造成的吗?

Aaron Betrand 在上面发表的评论

'Tools > Options > Query Execution > SQL Server > Advanced > Enable Parameterization for Always Encrypted. Is this checked.'

问题已解决。我以前一直在试验 Always Encrypted,并已将其删除,但此设置仍然存在,并且对过程进行了参数化,从而导致了此问题。

可能是 Always Encrypted 功能造成的。

如果您不打算使用参数化。您可以在声明变量后手动设置所有变量。
例如:
DECLARE @DB_String varchar(55)
SET @DB_String ='Redesign'

或者,您可以右击查询->连接->更改连接->选项>>找到[附加连接参数]页面->在该框区域,输入:
列加密设置=禁用
这也将禁用参数化。

如果您确实需要参数化来加密这些变量,目前看来您只能在查询级别进行。存储过程不能很好地与 Always Encrypted 一起使用,因为它可以被其他具有不同列加密设置的用户调用。