I am integrating SqlCacheDependency to use in my LinqToSQL datacontext.
I am using an extension class for Linq querys found here - http://code.msdn.microsoft.com/linqtos
All connections to the DB must be be dropped and user account with permissions used to enable the broker service.
The following would be ideal (replace databasename
):
IF ((SELECT is_broker_enabled FROM sys.databases WHERE name = '%DATABASE_NAME%') = 1)
BEGIN
ALTER DATABASE %DATABASE_NAME% SET NEW_BROKER WITH ROLLBACK IMMEDIATE;
END
ALTER DATABASE %DATABASE_NAME% SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE;
Also I suggest creating a new role and user account with the proper permissions (replace database login):
--DBA creates a new role
if not exists (select 1 from sys.database_principals where name='sql_dependency_subscriber' and Type = 'R')
begin
EXEC sp_addrole 'sql_dependency_subscriber'
end
--Minimum Required Permissions needed for SQLDependancy Notification to work
GRANT CREATE PROCEDURE to sql_dependency_subscriber;
GRANT CREATE QUEUE to sql_dependency_subscriber;
GRANT CREATE SERVICE to sql_dependency_subscriber;
GRANT REFERENCES on CONTRACT::[http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification] to sql_dependency_subscriber ;
GRANT VIEW DEFINITION TO sql_dependency_subscriber;
--Minimum Required Permissions needed for SQLDependaney Notification to work
GRANT SELECT to sql_dependency_subscriber;
GRANT SUBSCRIBE QUERY NOTIFICATIONS TO sql_dependency_subscriber;
GRANT RECEIVE ON QueryNotificationErrorsQueue TO sql_dependency_subscriber;
GRANT REFERENCES on CONTRACT::[http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification] to sql_dependency_subscriber ;
EXEC sp_addrolemember 'sql_dependency_subscriber', '%DATABASE_LOGIN%';
EXEC sp_addrolemember 'sql_dependency_subscriber', 'sqldp';