gpt4 book ai didi

SQL Server 存储过程因使用 XML/ANSI_NULLS、QUOTED_IDENTIFIER 选项而失败

转载 作者:数据小太阳 更新时间:2023-10-29 01:47:08 29 4
gpt4 key购买 nike

我有一个存储过程,它接受一个 XML 参数并将数据插入到多个表中。如果我使用 SSMS 查询窗口将存储过程运行到数据库中,一切正常。但是,我们有一个自定义安装程序,用于将存储过程部署到数据库,当使用它时,sp 的执行失败并出现此错误:

INSERT failed because the following SET options have incorrect settings:
'ANSI_NULLS, QUOTED_IDENTIFIER'. Verify that SET options are correct for use with
indexed views and/or indexes on computed columns and/or query notifications
and/or xml data type methods.

在存储过程中编写脚本时,自定义安装程序未使用正确的设置。

在 sp 中设置这些(SET ARITHABORT ON; SET QUOTED_IDENTIFIER ON; SET ANSI_NULLS ON;)无效:

我还尝试在代码中调用 sp 之前为打开的连接设置这些选项。这又没有达到预期的效果。

似乎在数据库中运行 sp 时连接到数据库的设置才是最重要的,不是使用 sp 时的设置.

我已经尝试在 SSMS 选项中使用这些设置,结果确实如此。 我只是希望有人确认这确实是这种情况(如果有办法我很想听听,但我不抱希望)

不幸的是,目前我无法更改安装程序,因此我正在考虑不得不回滚几周的工作;所以如果我确实必须这样做,我想真正确定(并有一些证据支持我)这是唯一的选择

最佳答案

在 CREATE 或 ALTER 时应用的设置在运行时被忽略。

默认情况下,SSMS 具有正确的设置(sqlcmd、osql 等也是如此)。

来自 BOL, CREATE PROC, "Using SET Options"

The Database Engine saves the settings of both SET QUOTED_IDENTIFIER and SET
ANSI_NULLS
when a Transact-SQL stored procedure is created or modified. These original settings are used when the stored procedure is executed. Therefore, any client session settings for SET QUOTED_IDENTIFIER and SET
ANSI_NULLS
are ignored when the stored procedure is running. Other SET options, such as SET ARITHABORT, SET ANSI_WARNINGS, or SET ANSI_PADDINGS are not saved when a stored procedure is created or modified.

关于SQL Server 存储过程因使用 XML/ANSI_NULLS、QUOTED_IDENTIFIER 选项而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1713953/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com