We are trying to implement SqlCacheDependency and while adding the dependency through Stored Procedure it remove the object immediately after adding it to cache.It gives CacheItemRemovedReason as 4.
We have used the Database Synchronization sample provided in mentioned below link.
http://www.alachisoft.com/resources/samples/
string storedProcName = "dbo.TestStoredProc1";
SqlCmdParams sqlParams = new SqlCmdParams();
sqlParams.Value = prod.ProductID;
//sqlParams.
Dictionary<string, SqlCmdParams> prms = new Dictionary<string, SqlCmdParams>();
prms.Add("ID", sqlParams);
_cache.Add(prod.ProductID.ToString(), item,DSWriteOption.None,null);
item.Dependency = new SqlCacheDependency(connString, "select * from dbo.state_lookup where state_id = " + prod.ProductID.ToString());
Database Synchronizationpublic void OnCacheDataModification(string key, CacheEventArg args)
{
switch (args.EventType)
{
case EventType.ItemAdded:
// Key has been added to the cache
Console.WriteLine(key + " Item Added");
break;
case EventType.ItemUpdated:
Console.WriteLine(key + " Item Updated");
break;
case EventType.ItemRemoved:
break;
}
I have added item change listener and it goes to ItemRemoved section immediatly after going into ItemAdded part.The item removed call back should get called only when data is changed in the database.
SQL Server Version : Microsoft SQL Server 2008 R2 (SP2)
Alachisoft Edition : Enterprise Trial Version
Alachisoft SDK version : 4.9.1.1