roger (nospam@rogerware.com) writes:
[quoted text, click to view] > I started out to use the .NET SqlDependency mechanism, based on
> QueryNotificationService if I have the vocab correct, and have run into
> a limitation that seems like it will prevent this from working out for
> me, at least in the way I had hoped and planned...
>
> Specifically, when adding a SqlDependency to a stored procedure, a
> subscription is (attempted) to be created on each statement inside the
> stored procedure. Even if the statement doesn't return any rows outside of
> the stored procedure, including internal selects and sets:
>
> select a, b, c from dbo.mytable -- fine
> select @err = @@error -- causes subscription error
>
> Effectively, this appears to mean that one can't use query notifications
> on anything but the most trivial of stored procedures (a single select
> statement)
>
> Seems to me that the only useful behavior would be to track the actual
> result(s) of the query - return parameters and actual result sets returned
> to the caller. Tracking each internal statement can't be good for anybody.
>
> Is there some good reason for this, or have I completely missed something?
Yes, there is a good reason. :-)
It's not that SQL Server is running the procedure over and over again to
see if the result changes. Rather you can see it as an internal trigger
that fires when there is a change to any of the underlying base tables in
query. In fact, the mechanism used are the same that are used to implement
indexed views. So the query cannot just be any query, but there are whole
set of rules for what queries for which you can set up notifications.
This is detailed on this topic in Books Online:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/3ba5271c-7efa-4a73-a2c4-b4730df3fdc3.htm
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at