sql - IS_ROLEMEMBER not working properly -


i need check whether user has role databasemailuserrole.

i tried this:

select is_member('databasemailuserrole')  select is_rolemember ('databasemailuserrole', '<loginname>') 

both return value either correct or incorrect.

this means several logins returns right value, others not.

databasemailuserrole sql server, aware of. issue logic databasemailuserrole database role, , therefore maps users, not logins.

users (database level) , logins (server level) distinct objects access database on server, user needs both login name , user name. login , user objects same person may, not required to, share same name

for example

create user someuser login 'domain\login'; go exec sp_addrolemember 'databasemailuserrole','someuser'; go  /* following fail because users can added database role databasemailuserrole */ exec sp_addrolemember 'databasemailuserrole','domain\login'; go     execute login = 'domain\login' select is_member('databasemailuserrole') -> true  /* login 'domain\login' has username someuser */  select current_user -> 'someuser' select system_user ->  'domain\login'   select is_rolemember ('databasemailuserrole', 'domain\login') -> null select is_rolemember ('databasemailuserrole', 'someuser') -> true 

therefore is_rolemember should called w/ arguments below:

select is_rolemember ('databasemailuserrole', '<user_name>')  /* user name 1 of following */ select name sys.database_principals type=n'u';  /* or */ select user_name() /* or */ select current_user 

you might getting correct results using logins names in cases because server level logins can mapped database level user same name.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -