我正在通过flyway migrate运行一些脚本,我在每个脚本中都会收到此错误。脚本本身运行但下一个脚本没有运行。
The prepared statement handle 3 is not valid in this context.
Please verify that current database, user default schema, and ANSI_NULLS and
QUOTED_IDENTIFIER set options are not changed since the handle is prepared.
上次脚本运行正常但我暂时没有执行它们。另一位开发人员在笔记本电脑上运行它们。我已在两台笔记本电脑上检查了ANSI_Nulls和Quoted_Identifier的默认设置,它们是相同的。
有一点需要注意的是,所有脚本在执行之前显式地将ANSI_NULLS和QUOTED_IDENTIFIER设置为ON,然后关闭它们,例如
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
IF OBJECT_ID(N'[dbo].[CalculateActionStatus]', N'FN') IS NULL
EXEC('CREATE FUNCTION [dbo].[CalculateActionStatus] (@Dummy int) RETURNS int AS BEGIN RETURN 1 END;')
GO
ALTER FUNCTION [dbo].[CalculateActionStatus]
(@ActionID int)
RETURNS int
AS
BEGIN
-- Action Status is basically the BIGGEST Status value of its child steps
DECLARE @Status int
set @Status = 0
select @Status = max(dbo.CalculateStepStatus(Start, Due, Completed, PercentComplete))
from dbo.view_Step_ResolutionStep
where ActionID = @ActionID
RETURN isnull(@Status, 0)
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
有什么想法吗?
答案 0 :(得分:0)
我遇到了这个问题,但这是因为我使用的是 JTDS 驱动程序。我改为使用 SQL 服务器驱动程序,它工作正常。这实际上也在 Flyway SQL Server Limitations 文档中注明。
JTDS 连接字符串;
flyway.url=jdbc:jtds:sqlserver://myserver:1433/mydb
SQL Server 连接字符串;
flyway.url=jdbc:sqlserver://myserver:1433;databaseName=mydb