How can we help you today? How can we help you today?
stan
Yes, I don't why this happens, here is the code I am trying: -- Testing for BACKUP rights. -- Work from server role to database role, to BACKUP DATABASE execution and restriction rights. -- # Aliases are not supported. DECLARE @hasrights INTEGER SELECT @hasrights = IS_SRVROLEMEMBER('sysadmin', 'dba') IF ( @hasrights = 0 ) OR ( @hasrights IS NULL ) BEGIN SETUSER 'dba' -- As long as the user has sysadmin server role, he can backup the database. SELECT @hasrights = IS_SRVROLEMEMBER('sysadmin') IF ( @hasrights = 0 ) OR ( @hasrights IS NULL ) BEGIN -- This has to be done because IS_SRVROLEMEMBER does not check recursively if a login name is provided. USE [MonitorMedios] DECLARE @login_type INTEGER DECLARE @login_name SYSNAME -- No sysadmin rights. Check for database db_owner role. SELECT @hasrights = IS_MEMBER('db_owner') -- Check for database db_backupoperator role. IF ( @hasrights <> 1 ) BEGIN SELECT @hasrights = IS_MEMBER('db_backupoperator') END -- No db_backupoperator role. Check BACKUP DATABASE execute rights. -- Quick check for explicit rights. IF ( @hasrights = 0 ) OR ( @hasrights IS NULL ) BEGIN SELECT @hasrights = 1 WHERE EXISTS ( SELECT 1 FROM sysprotects a INNER JOIN sysusers b ON a.uid = b.uid AND b.name = 'dba' WHERE a.action = 228 AND a.protecttype IN ( 204, 205 ) ) IF ( @hasrights = 0 ) OR ( @hasrights IS NULL ) BEGIN -- No direct rights. Now need to iterate and check all Windows groups and SQL Server roles. DECLARE cur_rights CURSOR FOR SELECT ( CASE WHEN b.isntgroup = 1 THEN 1 ELSE CASE WHEN b.issqlrole = 1 THEN 2 ELSE 0 END END ) type, b.name FROM sysprotects a INNER JOIN sysusers b ON a.uid = b.uid WHERE a.action = 228 AND a.protecttype IN ( 204, 205 ) AND ( b.isntgroup = 1 OR b.issqlrole = 1 ) OPEN cur_rights FETCH NEXT FROM cur_rights INTO @login_type, @login_name @FETCH_STATUS = 0 BEGIN SELECT @hasrights = IS_MEMBER(@login_name) IF @hasrights = 1 BEGIN BREAK END FETCH NEXT FROM cur_rights INTO @login_type, @login_name END CLOSE cur_rights DEALLOCATE cur_rights END END -- for database level rights, need to check if DENY restriction exists IF @hasrights = 1 BEGIN SELECT @hasrights = 0 WHERE EXISTS ( SELECT 1 FROM sysprotects a INNER JOIN sysusers b ON a.uid = b.uid AND b.name = 'dba' WHERE a.action = 228 AND a.protecttype IN ( 206 ) ) IF @hasrights = 1 BEGIN -- No explicit DENY restrictions. Check via group / role membership. DECLARE cur_rights CURSOR FOR SELECT ( CASE WHEN b.isntgroup = 1 THEN 1 ELSE CASE WHEN b.issqlrole = 1 THEN 2 ELSE 0 END END ) type, b.name FROM sysprotects a INNER JOIN sysusers b ON a.uid = b.uid WHERE a.action = 228 AND a.protecttype = 206 AND ( b.isntgroup = 1 OR b.issqlrole = 1 ) OPEN cur_rights FETCH NEXT FROM cur_rights INTO @login_type, @login_name @FETCH_STATUS = 0 BEGIN SELECT @hasrights = IS_MEMBER(@login_name) IF @hasrights = 1 BEGIN SET @hasrights = 0 BREAK END FETCH NEXT FROM cur_rights INTO @login_type, @login_name END CLOSE cur_rights DEALLOCATE cur_rights END END END SETUSER END DECLARE @dbname SYSNAME SELECT @dbname = name FROM master..sysdatabases WHERE name = N'MonitorMedios' IF @hasrights = 1 SELECT CAST(1 AS INT) AS hasrights, @dbname AS name ELSE SELECT CAST(0 AS INT) AS hasrights, @dbname AS NAME / comments
Yes, I don't why this happens, here is the code I am trying: -- Testing for BACKUP rights. -- Work from server role to database role, to BACKUP DATABASE execution and restriction rights. -- # Al...
0 votes
Where's the script SQL Backup uses for backup rights? do you mean runing the backup script SQL Backup creates for backing up the conflicting database? / comments
Where's the script SQL Backup uses for backup rights? do you mean runing the backup script SQL Backup creates for backing up the conflicting database?
0 votes