We are getting the below message sometimes while executing the stored procedure, after that without any change deleting and re-executing the stored procedure it is working fine.
QUOTED_IDENTIFIER
is a "sticky" option so the setting in effect when the procedure was created is used at runtime. Since no procedure changes were made, the error suggests the stored procedure was created with QUOTED_IDENTIFIER OFF
and an index with one of the types mentioned in the error message was created/dropped.
Recreate or alter the stored procedure from a session with both QUOTED_IDENTIFIER ON
and ANSI_NULLS ON
to avoid the problem going forward.
In my case I had to add -I parameter to sqlcmd.exe command line when loading stored procedures in the bulk mode.
I was running into this problem so I created all my Job's Steps into Stored procedures in MS SQL. When using the template it automatically has the following
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
If anyone hits this error after having deployed via a Visual Studio database project then it's worth checking the properties of your stored procedure file. If this is set to Project Default then go to the properties of your database project > Project Settings and click the Database Setting button.
You can turn these two values (and others) to be on by default as shown in the screenshot below.
This will only fix the issue if you have changes to the procedure how ever; a schema compare and subsequent update will not change the QUOTED_IDENTIFIER
in the stored procedure unless there are changes to the body of the procedure. It will prevent the problem from reoccurring on a subsequent schema updated though.