Troubleshooting Guide: SQL Server Error 4135 — Synonyms on Queues Not Allowed
Why This Error Happens
This error occurs because SQL Server’s Service Broker architecture explicitly prohibits the creation of synonyms that reference queue objects. Queues are specialized internal structures used strictly for message storage and retrieval within Service Broker conversations, and they do not support the abstraction layer that synonyms provide. When a developer or migration script attempts to create a synonym pointing to a queue object (rather than a table, view, or procedure), SQL Server 2025 rejects the DDL operation to maintain the integrity of the messaging subsystem.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Synonym and Queue
- Run a query against
sys.synonymsto locate the synonym referenced in the error message. - Use the following script to cross-reference the base object type:
SELECT name, base_object_name
FROM sys.synonyms
WHERE name = 'YourSynonymName';
- Confirm that the
base_object_namepoints to a Service Broker queue by checkingsys.service_queues.
Step 2: Drop the Invalid Synonym
- Since synonyms cannot legally wrap queue objects, the only immediate fix is removal.
- Execute the drop command in SQL Server Management Studio (SSMS) or via
sqlcmdon Windows Server 2025:
DROP SYNONYM dbo.YourSynonymName;
- Verify there are no dependent stored procedures or views still referencing this synonym before deletion.
Step 3: Redirect Application Logic to the Queue Directly
- Update your application code or stored procedures to reference the queue object directly using
SENDandRECEIVEstatements rather than relying on synonym abstraction. - Example direct reference syntax:
RECEIVE TOP(1) * FROM dbo.YourActualQueueName;
- Ensure connection strings and ORM mappings (e.g., Entity Framework) are updated to bypass the synonym layer for this specific object.
Step 4: Re-deploy and Validate Schema Scripts
- If this error surfaced during a database migration or DACPAC deployment on Windows Server 2025, check your source control schema files for legacy synonym creation scripts targeting queues.
- Remove these specific
CREATE SYNONYMstatements from your build pipeline (e.g., Azure DevOps or GitHub Actions YAML) to prevent recurrence in future deployments.
Alternative or Verification Steps
- Verification: Run
SELECT * FROM sys.synonyms WHERE base_object_name LIKE '%YourQueueName%';to confirm zero results are returned, verifying the orphaned synonym has been successfully purged. - Alternative: If the application architecture requires an abstraction layer for security reasons, create a stored procedure wrapper that internally executes the
RECEIVEstatement, and grantEXECUTEpermissions on that procedure instead of attempting to synonym-wrap the queue.