After much banging my head against the internet here is a canonical example of how to configure SQL Server permissions, roles to get SqlDependency working in a .Net app.
This is for sceneario where the identity running the .Net code is running as a configured user account with the db_datareader & db_datawriter.
-- Create Schema User
CREATE USER sql_dependency_schema_owner WITHOUT LOGIN;
GO
CREATE USER sql_dependency_schema_owner WITHOUT LOGIN;
GO
-- Create Schema for SqlDependency objects
CREATE SCHEMA sql_dependency AUTHORIZATION sql_dependency_schema_owner;
GO
-- Create Role for users of [sql_dependency]
CREATE ROLE sql_dependency_user;
GO
-- Grant role permissions
GRANT CONTROL ON SCHEMA::sql_dependency TO sql_dependency_user;
GRANT IMPERSONATE ON USER::sql_dependency_schema_owner TO sql_dependency_user;
GRANT CREATE PROCEDURE TO sql_dependency_user;
GRANT CREATE QUEUE TO sql_dependency_user;
GRANT CREATE SERVICE TO sql_dependency_user;
GRANT REFERENCES ON CONTRACT::[http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification] TO sql_dependency_user;
GRANT VIEW DEFINITION TO sql_dependency_user;
GRANT SELECT to sql_dependency_user;
GRANT SUBSCRIBE QUERY NOTIFICATIONS TO sql_dependency_user;
GRANT RECEIVE ON QueryNotificationErrorsQueue TO sql_dependency_user;
GO
-- Set [sql_dependency] as user default schema add to role, example user 'ollie'
ALTER USER ollie WITH DEFAULT_SCHEMA = sql_dependency;
ALTER ROLE sql_dependency_user ADD MEMBER ollie;
GO
Comments
Post a Comment