Is it possible to run a SqlDependency in C# for Sql Server without executing a query?
I have some tables that can grow fairly large. Executing a query across a table to tell if a row has changed can take a long time.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, SqlDependency requires an SqlCommand to execute.
If performance is a problem, you could think about alternative designs, such as adding a trigger to the table that is to be monitored and writing into an extract table each time a row changes then have the SqlDependency monitor the extract table instead.
If any row that changes in the original table should trigger the dependency, then your extract table could be as simple as a single row that contains a counter of the number of rows that have changed. When this value changes, the dependency would be triggered.
Alternatively, the extract table could just contain a timestamp for the last date/time that any row in the table was changed.