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

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 #TempTable or SELECT ... INTO dbo.NewTable pattern inside code using SqlDependency, SqlCacheDependency, or Service Broker WAITFOR(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 standard SELECT 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 SELECT for the notification/result set, then perform the INSERT INTO TargetTable SELECT... as an independent, non-notification statement.
  • Update the application’s C#/.NET code (or stored procedure) that constructs the SqlCommand object feeding SqlDependency, ensuring it only contains a flat SELECT statement meeting notification requirements (two-part table names, no SELECT *, no TOP, no INTO).

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 without GROUP BY, no UNION, no subqueries returning into temp objects).
  • Re-run sp_helptext on the stored procedure (if applicable) to confirm no other INTO clauses 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_subscriptions shows an active subscription, the issue is resolved.
  • If the error persists despite removing INTO, check for nested views or linked server calls that internally use SELECT...INTO, as these can also trigger the same error indirectly.