Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Drop a database user on a linked server. Expand / Collapse
Author
Message
Posted Friday, July 12, 2013 8:43 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, September 26, 2014 12:50 PM
Points: 14, Visits: 191
I have to be missing something as I can't seem to make this happen. I have 2 SQL 2012 boxes linked and have tried dozens of methods to delete a user from a database on the other server with no luck. I've tried various methods of "sys.sp_dropuser" and "Drop User".

Am I missing something?

Charlie



Post #1473077
Posted Friday, July 12, 2013 9:00 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:47 AM
Points: 13,001, Visits: 12,418
Charles Deaton (7/12/2013)
I have to be missing something as I can't seem to make this happen. I have 2 SQL 2012 boxes linked and have tried dozens of methods to delete a user from a database on the other server with no luck. I've tried various methods of "sys.sp_dropuser" and "Drop User".

Am I missing something?

Charlie


You have to drop the user from the instance where that user belongs. You can't drop remote users, that would be a HUGE security issue.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1473086
Posted Sunday, July 14, 2013 3:30 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 1:24 PM
Points: 805, Visits: 722
EXEC ('DROP USER thatuser') AT YourServer

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Post #1473400
Posted Monday, July 15, 2013 6:24 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, September 26, 2014 12:50 PM
Points: 14, Visits: 191
That wprk fine for dropping the user from the master database. Is it possible to specify the database I need?



Post #1473614
Posted Monday, July 15, 2013 7:22 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:47 AM
Points: 13,001, Visits: 12,418
Erland Sommarskog (7/14/2013)
EXEC ('DROP USER thatuser') AT YourServer


Thanks for the correction. I did not realize you could drop a user remotely like that.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1473642
Posted Monday, July 15, 2013 7:27 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:55 AM
Points: 12,902, Visits: 32,141
Charles Deaton (7/15/2013)
That wprk fine for dropping the user from the master database. Is it possible to specify the database I need?


just a a USE DatabaseName to the command, if the linked server didn't define the context for the database name :
EXEC ('Use SandBox; DROP USER thatuser;') AT YourServer 



Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1473644
Posted Monday, July 15, 2013 2:47 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 1:24 PM
Points: 805, Visits: 722
Very good correct Lowell!

Here's one that is slicker:

EXEC LinkedServer.yourdb.sys.sp_executesql N'DROP USER myuser'

Not the least is this one slick, if any of the items are variable:

DECLARE @sp_executesql nvarchar(1024) = 
quotename(@server) + '.' + quotename(@db) + '.sys.sp_executesql'
EXEC @sp_executesql N'DROP USER myuser'

Key here is that EXEC accepts a variable for the procedure name, and a system procedure always executes in the context of the database from which it is invoked.


Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Post #1473902
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse