How to fix Error 2274 on Windows Server 2025 / Windows 11

Why This Error Happens

Error 2274 occurs when the SQL Server query parser encounters a string literal that opens with a single or double quotation mark but never finds a matching closing quote before the batch or script ends. This is typically caused by an unescaped apostrophe inside string data (e.g., in names like “O’Brien”), a copy-paste error that truncates a query, or inconsistent QUOTED_IDENTIFIER settings between the client tool and the server session. In SQL Server 2025, this can also surface when migrating legacy scripts that rely on deprecated string concatenation behaviors now flagged more strictly by the updated parser.

Step-by-Step Resolution Guide

Step 1: Isolate the Offending Line

  • Note the line number referenced in the error message (started on line %u) — this points to the exact origin of the unclosed string, not necessarily where the error surfaces.
  • Open the script in SQL Server Management Studio (SSMS) 21 or Azure Data Studio and navigate directly to that line using Ctrl+G (Go To Line).
  • Visually scan for a lone single quote (') that lacks a matching pair later in the statement.

Step 2: Escape or Correct Embedded Quotes

  • If the string contains a literal apostrophe (e.g., 'Mary's Diner'), double it so SQL Server treats it as a literal character: 'Mary''s Diner'.
  • For dynamic SQL built in application code or stored procedures, verify string concatenation logic isn’t stripping or misplacing quote characters before execution.
  • If using QUOTENAME() or REPLACE() functions to sanitize input, confirm they are applied before the string is passed into the final EXEC() or sp_executesql call.

Step 3: Validate QUOTED_IDENTIFIER and Compatibility Level

  • Run the following to check current session settings:
  SELECT SESSIONPROPERTY('QUOTED_IDENTIFIER');
  • Ensure it matches the setting used when the object (procedure, view, function) was originally created, as mismatches can cause the parser to misinterpret double quotes as identifiers instead of string delimiters.
  • If the database was recently upgraded, verify compatibility level under Database Properties > Options in SSMS (right-click database → Properties → Options → Compatibility Level) matches SQL Server 2025 expectations (160 or higher).

Step 4: Re-run the Script in Isolation

  • Copy only the suspect batch (between GO statements) into a new query window.
  • Execute it alone using Ctrl+E to confirm whether the error is isolated to that specific batch rather than a cascading issue from an earlier unclosed string in the same file.

Alternative or Verification Steps

  • To verify the fix, execute the corrected script in a transaction with BEGIN TRAN / ROLLBACK to confirm it parses and runs without raising Error 2274, then commit once confirmed.
  • If the error persists in complex dynamic SQL, use PRINT @SQL before execution to output the fully constructed string to the Messages tab — this visually reveals where the quote is actually breaking, which is often different from where the script editor highlights it.