Why This Error Happens
Error 13016 occurs when a SELECT...INTO statement is used inside a query that is registered for Query Notifications or submitted through a Service Broker-dependent command (such as SqlDependency or SqlNotificationRequest in an application). SQL Server’s notification engine requires the query to return a result set directly to the client connection; because INTO redirects output into a new table rather than returning rows, the engine cannot track or validate the result set, so it rejects the statement before execution. This is a query-shape restriction, not a permissions or connectivity issue.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Query
- Check the application log or SQL Server error log for the exact statement text tied to Error 13016.
- Look for any
SELECT ... INTO #TempTableorSELECT ... INTO dbo.NewTablepattern inside code usingSqlDependency,SqlCacheDependency, or Service BrokerWAITFOR(RECEIVE...)activation procedures. - In SQL Server Management Studio (SSMS), run
SELECT * FROM sys.dm_qn_subscriptions;to confirm whether the query is registered as a notification subscription.
Step 2: Rewrite the Query to Remove the INTO Clause
- Replace
SELECT col1, col2 INTO #Temp FROM dbo.Table1 WHERE ...with a standardSELECT col1, col2 FROM dbo.Table1 WHERE .... - If you need to persist data into a table, separate the logic into two steps: first run the plain
SELECTfor the notification/result set, then perform theINSERT INTO TargetTable SELECT...as an independent, non-notification statement. - Update the application’s C#/.NET code (or stored procedure) that constructs the
SqlCommandobject feedingSqlDependency, ensuring it only contains a flatSELECTstatement meeting notification requirements (two-part table names, noSELECT *, noTOP, noINTO).
Step 3: Validate Query Notification Requirements
- Confirm the query also meets other Query Notification restrictions (explicit column names, two-part naming convention
schema.table, no aggregates withoutGROUP BY, noUNION, no subqueries returning into temp objects). - Re-run
sp_helptexton the stored procedure (if applicable) to confirm no otherINTOclauses remain in nested calls. - In Windows Server 2025 / Windows 11 hosts, restart the SQL Server Service Broker dependent service or recycle the application pool (IIS) if the notification subscription was cached with the old malformed query.
Step 4: Re-deploy and Test
- Push the corrected stored procedure or application code to the SQL Server 2025 instance.
- Use
sqlcmd -S <ServerName> -Q "EXEC sp_recompile 'dbo.YourProcName';"to force recompilation and clear any cached invalid plan.
Alternative or Verification Steps
- Verify the fix by re-executing the query manually in SSMS; if no Error 13016 appears and
sys.dm_qn_subscriptionsshows an active subscription, the issue is resolved. - If the error persists despite removing
INTO, check for nested views or linked server calls that internally useSELECT...INTO, as these can also trigger the same error indirectly.