Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_droplinkedsrvlogin

  No additional text.


Syntax
create procedure sys.sp_droplinkedsrvlogin
	@rmtsrvname		sysname,
	@locallogin		sysname
as
	declare @localid	int

	-- DISALLOW USER TRANSACTION
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_droplinkedsrvlogin')
		return (1)
	end

	-- CHECK PERMISSIONS
	if not (has_perms_by_name(null, null, 'alter any login') = 1)
	begin
		EXEC %%System().AuditEvent(ID = 1380207692, Success = 0, TargetLoginName = @locallogin, TargetUserName = NULL, Role = NULL, Object = NULL, Provider = NULL, Server = @rmtsrvname)
		raiserror(15247,-1,-1)
		return (1)
	end
	else
		EXEC %%System().AuditEvent(ID = 1380207692, Success = 1, TargetLoginName = @locallogin, TargetUserName = NULL, Role = NULL, Object = NULL, Provider = NULL, Server = @rmtsrvname)
	
	BEGIN TRAN

	-- VALIDATE/LOCK SERVER NAME 
	EXEC %%LinkedServer ( Name = @rmtsrvname ) . Lock ( Exclusive = 1 )
	IF @@ERROR <> 0
	begin
		ROLLBACK TRAN
		raiserror(15015,-1,-1,@rmtsrvname)
		return (1)
	end

	-- CHECK LOCAL USER NAME IF GIVEN
	select @localid = 0
	if @locallogin is not null
	begin
		-- share-lock the local login
		EXEC %%LocalLogin ( Name = @locallogin ) . Lock ( Exclusive = 0 )
		IF @@ERROR = 0
			select @localid = principal_id from sys.server_principals
				where name = @locallogin and type in ('S', 'U')
		if @localid = 0
		begin
			-- THERE WILL BE NO LinkedLogins, SO ONLY AN ERROR IF NO NT-NAME OUT THERE 
			IF suser_sid(@locallogin) IS NULL
			BEGIN
				ROLLBACK TRAN
				raiserror(15007,-1,-1,@locallogin)
				return (1)
			END

			-- "SUCCESS" 
			COMMIT TRAN
			return(0)
		end
	end

	-- IF MAPPING EXISTS FOR THIS SID, REMOVE IT 
	IF EXISTS (SELECT * FROM sys.linked_logins WHERE
			server_id IN (SELECT server_id FROM sys.servers where name = @rmtsrvname)
			AND local_principal_id = @localid)
	BEGIN
		EXEC %%LinkedServer(Name=@rmtsrvname).RemoveLinkedLogin(LocalID=@localid)
	END

	-- EMDEventType(x_eet_Drop_Linked_Server_Login), EMDUniversalClass(x_eunc_Linked_Server), src major id, src minor id, src name
	-- -1 means ignore target stuff, target major id, target minor id, target name,
	-- # of parameters, 5 parameters
	EXEC %%System().FireTrigger(ID = 236, ID = 102, ID = 0, ID = 0, Value = @rmtsrvname,
		ID = 101, ID = @localid, ID = 0, Value = NULL,
		ID = 2, Value = @rmtsrvname, Value = @locallogin, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

	-- SUCCESS 
	COMMIT TRAN
	return(0) -- sp_droplinkedsrvlogin

 
Last revision 2008RTM
See also

  sp_MSprocesslogshipmonitorlink (Procedure)
sp_MSprocesspublisherlink (Procedure)
sp_vupgrade_heterogeneous_publishers (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash