This code works fine, it invalidates the data whenever it is changed in the database:
AggregateCacheDependency aggDep = new AggregateCacheDependency();
System.Data.SqlClient.SqlCommand ocom = new System.Data.SqlClient.SqlCommand();
SqlCacheDependency SqlDep = new SqlCacheDependency("DBNAMEINCONFIG", "Products");
aggDep.Add(SqlDep);
I cannot have a straight invalidate on the entire "Products" table though, I need to be able to invalidate a selection on the table. The problem I'm having is the following code does not ever invalidate the cache when the data is changed:
AggregateCacheDependency aggDep = new AggregateCacheDependency();
System.Data.SqlClient.SqlCommand ocom = new System.Data.SqlClient.SqlCommand();
ocom.CommandText = "SELECT ID,ClinicID,Price,Enabled FROM dbo.Products WHERE ClinicID = 1";
ocom.Connection = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["DBSTRING"].ToString());
SqlCacheDependency SqlDep = new SqlCacheDependency(ocom);
aggDep.Add(SqlDep);
I tried to include all the information necessary to analyze this, but please let me know if I should include more!
As competent_tech pointed out there are quite a few rules for the queries used to build
SqlCacheDependency
. According to this MSDN article the most important are:Beside those rules it is important to execute the
SqlCommand
used to build theSqlCacheDependency
in order to enable the query notification:Hope, this helps.