Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Specific user account access only


Specific user account access only

Author
Message
krypto69
krypto69
SSC Eights!
SSC Eights! (869 reputation)SSC Eights! (869 reputation)SSC Eights! (869 reputation)SSC Eights! (869 reputation)SSC Eights! (869 reputation)SSC Eights! (869 reputation)SSC Eights! (869 reputation)SSC Eights! (869 reputation)

Group: General Forum Members
Points: 869 Visits: 2420
Hi,

I'm doing some DR testing. Is there a way I can disable all access to a Database, except for one specific user?

My DB has 800 logins, and I want to disable all access during my DR testing, but during this testing my Report user account (one user) should be able to access the data (read only).

Is there a script or a way to accomplish this?



Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14955 Visits: 38948
i think it's the usual; there's no easy way, but you can use the metadata to build your commands to add everyone to a deny everything group
something like this is what i think off of the top of my head.


CREATE ROLE [NoAccessForYou];
ALTER AUTHORIZATION ON SCHEMA::[db_denydatawriter] TO [NoAccessForYou];
ALTER AUTHORIZATION ON SCHEMA::[db_denydatareader] TO [NoAccessForYou];

CREATE ROLE [OnlyReadAccessForYou];
ALTER AUTHORIZATION ON SCHEMA::[db_denydatawriter] TO [OnlyReadAccessForYou];
ALTER AUTHORIZATION ON SCHEMA::[db_datareader] TO [OnlyReadAccessForYou];

declare @Batch varchar(max);
SET @Batch = '';
SELECT --@Batch = @Batch +
'EXEC sp_addrolemember N''NoAccessForYou'', N''' + name + ''';' + CHAR(13) + CHAR(10),*
FROM sys.database_principals WHERE type_desc IN('WINDOWS_USER','SQL_USER') AND principal_id > 4 ;
print (@Batch);
--exec (@@Batch);

EXEC sp_droprolemember N'NoAccessForYou', N'TestUser';
EXEC sp_addrolemember N'OnlyReadAccessForYou', N'TestUser';


EXECUTE AS USER='TestUser';
--do stuff


--change back into superman
REVERT;

--clean up after ourself:
DROP ROLE [OnlyReadAccessForYou];
DROP ROLE [NoAccessForYou];




Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

krypto69
krypto69
SSC Eights!
SSC Eights! (869 reputation)SSC Eights! (869 reputation)SSC Eights! (869 reputation)SSC Eights! (869 reputation)SSC Eights! (869 reputation)SSC Eights! (869 reputation)SSC Eights! (869 reputation)SSC Eights! (869 reputation)

Group: General Forum Members
Points: 869 Visits: 2420
lol...never is that easy..

thanks man, that's just what I was looking for..



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search