Joab Santos
Joab Santos

Reputation: 522

C# SqlCacheDependency - Should I have to EnableNotifications and EnableTableForNotifications Whenever my application is ran?

I'm wondering if I have to execute this code whenever my application is ran or once I ran it, my database is now set to clean my cache whenever determined table specified is changed.

System.Web.Caching.SqlCacheDependencyAdmin.EnableNotifications(cs); 

System.Web.Caching.SqlCacheDependencyAdmin.EnableTableForNotifications(cs, "TABLENAME");

Upvotes: 0

Views: 316

Answers (1)

William Xifaras
William Xifaras

Reputation: 5312

You can EnableNotifications and EnableTableForNotifications in the place that sets up the SqlCacheDependency.

Don't forget that if you want to disable this, you will have to call DisableNotifications and / or DisableTableForNotifications.

That being said, you should start and stop the listener in the Application_Start and Application_End methods.

protected void Application_Start(object sender, EventArgs e)
{  
    SqlDependency.Start("YOUR CONNECTION STRING");
}

protected void Application_End(object sender, EventArgs e)
{
    SqlDependency.Stop("YOUR CONNECTION STRING");
}

More info here.

Upvotes: 2

Related Questions