I have an ASP.NET application running on multiple IIS6 web servers, with a SQL Server 2005 database back-end.
I need to:
monitor the database for the completion of an external job event, and then
have exactly one web application instance submit some information to a web service
For (1) it seems like a SqlDependency would be the best approach (or just plain old polling). Each web application instance would register such a dependency when it starts up. (I don't want to configure a 'master' instance because the failure of that instance would mean the task doesn't proceed, even if other instances are available. Thus my design is to ensure that if there is an instance available to do the work, then the work ought to proceed.)
For (2) I have been thinking of having some sort of flag in the database that the web application instances try to update once they receive the SqlDependency notification in (1), along the following line (greatly simplified):
UPDATE StatusTable SET TaskStatus = 1 WHERE TaskStatus = 0
SELECT @@ROWCOUNT
The idea is that only one application instance would have been able to update the TaskStatus, and thus only one instance would have a @@ROWCOUNT > 0. This would then be the instance 'elected' to submit the information to the web service.
What are the deficiencies with this approach? What are my other options? (Note: a separate service doing this work is not an option.)