NCache as Entity Framework second level cache not syncing with database

笑着哭i 提交于 2019-12-24 05:55:20

问题


Using NCache 4.6 as EF 6.1.3 second level cache, SqlDependency is not working. (It cant detect changes that I make directly in SQL server. Also does not update cache or invalidate it when using EF to add or delete entities to database. Albeit it detect updating an entity)

I've installed NCache in my computer with IP: 192.168.56.1 and SQL server 2014 in vbox with IP: 192.168.56.101

using instruction from their site and customizing them to meet my IP & user, I executed following SQL:

ALTER DATABASE NORTHWND SET ENABLE_BROKER with rollback immediate;
GO
--Select is_broker_enabled from sys.databases where name ='NORTHWND'

GRANT SUBSCRIBE QUERY NOTIFICATIONS TO user1
GRANT CREATE QUEUE TO user1
GRANT CREATE SERVICE TO user1
GRANT CREATE PROCEDURE TO user1


CREATE QUEUE "NCacheSQLQueue-192.168.56.1";
CREATE SERVICE "NCacheSQLService-192.168.56.1" ON QUEUE."NCacheSQLQueue-192.168.56.1"([http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]);

GRANT SUBSCRIBE QUERY NOTIFICATIONS TO user1;
GRANT RECEIVE ON "NCacheSQLQueue-192.168.56.1" TO user1;
GRANT RECEIVE ON QueryNotificationErrorsQueue TO user1;
GRANT SEND ON SERVICE :: "NCacheSQLService-192.168.56.1" to user1;

Also, select * from sys.dm_qn_subscriptions shows that no one is subscribed.


回答1:


It turns out that I needed to run ALTER AUTHORIZATION ON DATABASE::[NORTHWND] TO user1;.

Here is what I did:

1- restored a fresh Northwind database.

2- ran following SQL:

ALTER DATABASE NORTHWND SET ENABLE_BROKER with rollback immediate;
GO

GRANT SUBSCRIBE QUERY NOTIFICATIONS TO sa
GRANT CREATE QUEUE TO sa
GRANT CREATE SERVICE TO sa
GRANT CREATE PROCEDURE TO sa

ALTER AUTHORIZATION ON DATABASE::[NORTHWND] TO sa

Note that in this query I intentionally omitted CREATE QUEUE "NCacheSQLQueue-192.168.56.1"; and all queries after that.

Also, I found out that Entity Framework Profiler is incompatible with either NCache or SQL Dependency, so I disabled it.



来源:https://stackoverflow.com/questions/37915095/ncache-as-entity-framework-second-level-cache-not-syncing-with-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!