必须删除与数据库的所有连接,并使用具有启用代理服务权限的用户帐户。
以下将是理想的(替换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;
另外我建议创建一个具有适当权限的新角色和用户帐户(替换数据库登录):
--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';