Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
Administration
»
Query
Query
Rate Topic
Display Mode
Topic Options
Author
Message
Austin_123
Austin_123
Posted Thursday, August 05, 2010 1:17 PM
SSC-Addicted
Group: General Forum Members
Last Login: Friday, May 10, 2013 10:37 AM
Points: 447,
Visits: 366
Hi All,
Below query will drop all access for specified user from the user database.
DECLARE C1 CURSOR FOR
SELECT NAME FROM MASTER.DBO.SYSDATABASES
WHERE DBID > 4
AND DATABASEPROPERTYEX(name, 'Status') = 'ONLINE'
OPEN C1
FETCH NEXT FROM C1
INTO @SR
WHILE(@@FETCH_STATUS <> -1)
BEGIN
SET @CMD = 'USE [' +@SR + ']' + @NL +
'IF EXISTS (SELECT NAME FROM DBO.SYSUSERS WHERE NAME LIKE N''domain\user'')' + @NL +
'EXEC SP_REVOKEDBACCESS N''domain\user'' + @NL +
PRINT 'DROPPING THE ACCOUNT FROM ' + @SR + '....'
EXEC (@CMD)
FETCH NEXT FROM C1
INTO @SR
END
CLOSE C1
DEALLOCATE C1
-- @NL is CHAR(13)
with some databases when users have created with username as below
lf login is : WIN\Austin then with some database it has created
'Austin' only (no domail prefix) and yes login has referred to WIN\Austin.
Above code works ok when both login and user on db are same but it fails when users have been created without domain prefix.
I am thinking to store the output of below command in a variable.
SELECT name from dbo.sysusers where SID = SUSERS_SID(N'WIN\Austin')
I am not sure how to integrate this with main code. In other words If I store the output of above query then how can I pass the variable as parameter for SP_REVOKEDBACCESS @name_in_db or is there any way to execute the query as parameter for sp.
Thanks in advance.
Regards,
Austin
Post #964652
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.