title: SqlDependency Losing Subscription Over Time
body: <p>I've been using <a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency(v=vs.110).aspx" rel="noreferrer">SqlDependency</a> in a .NET 3.5 application for over 3 years without any problems.  The scenario is as follows:</p>
  
  <ol>
  <li>Central windows service with a <a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency(v=vs.110).aspx" rel="noreferrer">SqlDependency</a> watching a table (let's call this Table A)</li>
  <li>Multiple users using a WPF application with a unique <a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency(v=vs.110).aspx" rel="noreferrer">SqlDependency</a> per user watching a table (Table A again)</li>
  <li>User queues a unit of work for processing in Table A</li>
  <li><a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency(v=vs.110).aspx" rel="noreferrer">SqlDependency</a> fires on windows service</li>
  <li>Windows service processes all outstanding items in Table A and saves results to Table A</li>
  <li>Unique SqlDependency fires for each user who's results are available</li>
  <li>User processes their work</li>
  </ol>
  
  <p>Recently I've upgraded the system to .NET 4.5 and started seeing issues where changes would be put into the table we're monitoring, but the <a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency(v=vs.110).aspx" rel="noreferrer">SqlDependency</a> would never fire (both in the service and in the user application).  I started digging into this further and noticed in my logs that at some point I would re-register the <a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency(v=vs.110).aspx" rel="noreferrer">SqlDependency</a>, but then the notification would never fire after that.</p>
  
  <p>After seeing this behavior, I decided to run the profiler on SQL server to capture subscription events.  From the data that was captured, I noticed that sometimes a subscription would be registered (with a unique ID) by one user but then it would be fired (with the same unique ID) by another user.  This typically happens with the service I mentioned above and one or more of the users of the WPF application. (I've attached a screenshot of the the issue in the profiler results)</p>
  
  <p>Is this expected behavior?  That a notification can be fired for a different user than it was registered by?  Does this point to a problem in the application layer?  Any help is appreciated.</p>
  
  <p><a href="http://oi44.tinypic.com/28rlamo.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/EQzBx.png" alt="Profiler Results"></a></p>