Troubleshooting Guide: SQL Server Error 5311 – Invalid Quote Character
Why This Error Happens
Error 5311 occurs when SQL Server 2025 parses a remote server definition, linked server command, or distributed query that contains an unmatched or unsupported quote character (', ", or extended Unicode quote variants) in an identifier or connection string. This is frequently triggered by copy-pasted T-SQL from word processors or web sources that silently convert straight quotes into “smart quotes” (curly quotes), which the SQL parser cannot interpret. It can also happen when a linked server or OPENQUERY command references an object name with inconsistent quoting (mixing single quotes and double quotes incorrectly) or when the collation/code page of the client doesn’t match the server, corrupting the quote character during transmission.
Step-by-Step Resolution Guide
Step 1: Identify and Inspect the Offending Command
- Locate the exact T-SQL statement referenced in the SQL Server error log or Activity Monitor at the time Error 5311 was raised.
- Check
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOGfor the full statement text. - Look specifically for linked server calls,
sp_addlinkedserver,OPENQUERY, orEXECUTE ATstatements.
Step 2: Replace Smart Quotes with Standard ASCII Quotes
- Open the script in a plain text editor like Notepad or VS Code (avoid Word or rich-text editors).
- Use Find & Replace to swap curly quotes (
’ ‘ “ ”) with straight ASCII equivalents ('and"). - Re-run the corrected script directly in SQL Server Management Studio (SSMS) rather than pasting from an external source.
Step 3: Validate Linked Server and Identifier Syntax
- Confirm that linked server names and four-part object identifiers use consistent bracket or quote delimiters (e.g.,
[ServerName].[Database].[Schema].[Table]). - Run
sp_linkedserversto review existing configurations for malformed quoting. - Rebuild the linked server definition using
EXEC sp_addlinkedserverwith explicit, correctly escaped string literals if corruption is suspected.
Step 4: Check Client and Server Collation/Code Page Alignment
- Verify client driver settings (ODBC/OLE DB) are using UTF-8 or a matching code page to the SQL Server instance.
- Open SQL Server Configuration Manager > Client Protocols and ensure encoding settings align with server configuration.
- Restart the SQL Server service after any configuration change via
services.mscornet stop MSSQLSERVER && net start MSSQLSERVER.
Alternative or Verification Steps
- Re-execute the corrected query in SSMS and confirm no Error 5311 appears in the Messages pane or
ERRORLOG. - If the issue persists, recreate the linked server from scratch using
sp_dropserverfollowed bysp_addlinkedserver, typing all quotes manually rather than copy-pasting to rule out character encoding corruption.