Troubleshooting Guide: SQL Server Error 9204 – Invalid Query Notification Subscription Timeout
Why This Error Happens
This error occurs when the timeout parameter passed to the SqlDependency or SubscribeServiceBroker notification request falls outside the acceptable 32-bit integer range of 1 through 2,147,483,647. In most cases, this is caused by application code passing a negative value, zero, a null-converted default, or an improperly cast variable (such as a long or unvalidated user input) to the SqlCommand.Notification.Timeout property. It can also happen if a configuration file or connection string template contains a placeholder value that was never replaced with a valid integer before deployment.
Step-by-Step Resolution Guide
Step 1: Inspect the Application Code for the Timeout Value
- Locate where
SqlDependency.Start()orSqlCommand.Notificationis being configured in your .NET or application source code. - Check for lines similar to
command.Notification.Timeout = ...and verify the value is a positive integer. - Search for any configuration keys (e.g.,
appsettings.json,web.config) that feed this value dynamically, since a missing key often defaults to0or-1.
Step 2: Validate and Hardcode a Safe Default Timeout
- Set an explicit, safe timeout value (e.g.,
SqlDependency.Start(connectionString, queue); command.Notification = null; command.NotificationAutoEnlist = true;or manually setnew SqlNotificationRequest(options, 60)using a reasonable value like60to3600seconds). - Avoid using
int.MaxValueunless indefinite notification is explicitly required, as this can cause resource exhaustion on Windows Server 2025 under default Service Broker settings. - Rebuild and redeploy the application to ensure the compiled binary reflects the corrected value.
Step 3: Verify Service Broker Configuration on SQL Server 2025
- Open SQL Server Management Studio (SSMS) and connect to the instance.
- Run the following T-SQL to confirm Service Broker is enabled on the target database:
SELECT name, is_broker_enabled FROM sys.databases WHERE name = 'YourDatabaseName';
- If
is_broker_enabledreturns0, enable it using:
ALTER DATABASE YourDatabaseName SET ENABLE_BROKER;
Step 4: Check for Corrupted or Legacy Connection String Templates
- Navigate to
C:\inetpub\wwwroot\YourApp\Web.config(IIS-hosted apps) or the equivalentappsettings.jsonpath on Windows Server 2025. - Search for any residual template tokens like
{{TIMEOUT}}or$(DefaultTimeout)that may not have been substituted during deployment pipelines. - Replace any such placeholders with a concrete numeric value and restart the World Wide Web Publishing Service (
iisresetfrom an elevated PowerShell prompt) or the application pool.
Step 5: Restart SQL Server Service to Clear Cached Notification Requests
- Open Services.msc on Windows Server 2025.
- Locate SQL Server (MSSQLSERVER) or your named instance, right-click, and select Restart.
- Confirm no other notification subscriptions are queued with invalid parameters by querying
sys.dm_qn_subscriptions.
Alternative or Verification Steps
- Run
SELECT * FROM sys.dm_qn_subscriptions;in SSMS after redeploying the fix to confirm active subscriptions show a valid, non-nulltimeoutvalue. - If the error persists, bypass custom timeout logic entirely by using the overload
new SqlNotificationRequest("MyService", "MyQueue", SqlNotificationInfo.Default), which lets SQL Server apply its internal default timeout instead of a user-supplied one.