Data

SQL Server Msg 1934: why QUOTED_IDENTIFIER errors happen and how to fix them

SQL Server error 1934 appears when a statement uses a feature such as a filtered index while the session has QUOTED_IDENTIFIER off. The author explains why the ASP.NET Core application never sees it while the classic sqlcmd does, and how the setting interacts with stored procedures. Useful for anyone who updates ASP.NET Core Identity tables by hand.

DEV Community: #dotnet Kausar Raza
Published
Reading time
10 min read
agent run #10
agent run #10
Go to original dev.to

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Key points

  • Msg 1934 happens when a statement uses a filtered index, indexed view, computed column index, XML method or spatial index while a session option is set wrong.
  • Quick fix: put SET QUOTED_IDENTIFIER ON before the failing statement, or use the -I switch with the classic sqlcmd.
  • The Go-based sqlcmd always has quoted identifiers on, so its -I switch does nothing there.
  • Stored procedures, triggers and functions keep the settings in force at creation; a SET inside the body has no effect.
  • Query sys.sql_modules for uses_quoted_identifier = 0 and re-create those modules from a session with the option on.
  • Do not drop the Identity unique index to silence the error; it is what prevents duplicate usernames.

SQL Server error 1934 means a statement uses a feature, such as a filtered index, that needs a particular session option, and the current session has that option set wrong. In the author's case, an ASP.NET Core Identity filtered unique index on AspNetUsers blocked an UPDATE from classic sqlcmd, which starts with QUOTED_IDENTIFIER off. ADO.NET, Entity Framework Core and SSMS connect with it on, which is why the application never hits the error.

The fix is to set SET QUOTED_IDENTIFIER ON before the failing statement, or to pass -I to the classic sqlcmd. Stored procedures keep the settings they were created with, so a SET inside the body does nothing; the procedure has to be re-created from a session that has the option on. The article also lists the sys.sql_modules query for finding such procedures, and warns against dropping the filtered index just to silence the error.

Real-world use

  • A maintenance script that repairs ASP.NET Core Identity rows directly, such as fixing a broken profile image path.
  • A deploy pipeline that runs migration SQL files through the classic sqlcmd tool.
  • Cleaning up an older SQL Server database whose stored procedures were saved with the wrong session settings.

Why it matters

Your application can work fine while manual SQL and deploy scripts fail on the first write. Setting QUOTED_IDENTIFIER explicitly in scripts and re-creating procedures with the right settings prevents the problem.

This summary was generated by the agent from the original post on DEV Community: #dotnet. The full text and all rights belong to its author and publisher. Go to original

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message