Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6727961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:06:45+00:00 2026-05-26T10:06:45+00:00

many people seem to have problem in making this work, so i am not

  • 0

many people seem to have problem in making this work, so i am not new to here, hoping someone would be able to point out what else i can check, this is what i am doing…

Environment : .net 4.0, SQL Server Exrpress 2008 R2

Steps taken to setup the database

CREATE QUEUE WebSiteCacheMessages ;

CREATE SERVICE WebCacheNotifications ON QUEUE WebSiteCacheMessages
  ([http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]) ;
CREATE ROUTE WebCacheMessagesRoute WITH SERVICE_NAME = 'WebCacheNotifications',ADDRESS = 'LOCAL' ;

EXEC sp_configure 'show advanced options', '1'
GO
RECONFIGURE
GO
EXEC sp_configure 'clr enabled', 1
GO
RECONFIGURE
GO

ALTER DATABASE EFTest SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE
GO     
ALTER AUTHORIZATION ON DATABASE::[EFTEST] TO [domain\user];
GO

Following code to test the notification

     static void Main(string[] args)
        {
            var id = 0;
            string sqlStatement = "SELECT [Id] ,[FirstName],[LastName],[Email] FROM [dbo].[People]";
            string queueName = "WebSiteCacheMessages";
            string connectionString = ConfigurationManager.ConnectionStrings["MyDataContext"].ConnectionString;
            try
            {

                SqlDependency.Start(connectionString, queueName);
                using (var db = new DataContext(connectionString))
                {
                    var person = new Person { Email = "test@test.com", FirstName = "Testy", LastName = "Tester", HomeAddress = address };
                    db.Persons.Add(person);
                    db.SaveChanges();
                    id = person.Id;
                }
                var dependency = new SqlDependency();
                dependency.AddCommandDependency(new SqlCommand(sqlStatement));
                dependency.OnChange += (o, e) =>
                {
                    Console.WriteLine("Notification called !");
                };
                Console.ReadLine();
            }
            finally
            {
                SqlDependency.Stop(connectionString, queueName);
            }
        }

when i run an update statement on the email column in query window on sql server, i dont see on change event being fired.

There are no events in the event log or database logs, and when i run the following query, i dont see anything

select * from WebSiteCacheMessages -- queue name
select * from sys.transmission_queue

many thanks for reading through this…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:06:45+00:00Added an answer on May 26, 2026 at 10:06 am

    You don’t actually execute any command with a SqlDependency on it. You simply associate the SqlDependency with a SqlCommand, but you don’t actually execute the SqlCommand. The Query Notification on server gets created only when you execute the SQL statement. Something like:

    var dependency = new SqlDependency();
    var SqlCommand cmd = new SqlCommand(sqlStatement);
    dependency.AddCommandDependency(cmd);
    dependency.OnChange += (o, e) =>
    {
        Console.WriteLine("Notification called !");
    };
    
    // Executing the command will submit the query notification request
    using (SqlDataReader rdr = cmd.ExecuteReader ()) {
       while (rdr.Reader ()) {
          ...
       }
    }
    Console.Reade ();
    

    Another alternative is to use LinqToCache and query your DataContext.Persons:

    var people = from p in db.Persons select new {p.Id, p.LastName, p.FirstName, p.Email};
    var peopleCached = people.AsCached("Persons", new QueryCachedOptions () {
      OnInvalidate = (sender, args) => {
        Console.WriteLine("Notification called !");
      }
     });
    // Again, the underlying SqlCommand must actually be executed. Iterate the query
    foreach (p in peopleCached ) {
     ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know many people have had this problem and I have searched Google/Stack Overflow,
Many Flex books seem to focus on people new to programming. E.g. I bought
We have many instances in our application where we would like to be able
So here's my problem: I cannot seem to be able to configure CruiseControl.NET to
I have tried solving this problem by posting other related questions here that focused
I know many people experience this problem, but the solutions I found online do
I've been trying to find the answer to this question here. Several people seem
Many people ask me why, and I don`t have a good answer for them.
Many people have argued about function size. They say that functions in general should
Like many people here, I started my programming experience with the good ol' green

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.