Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_dropremotelogin

  No additional text.


Syntax
create procedure sys.sp_dropremotelogin
	@remoteserver	sysname,			-- name of remote server
	@loginame		sysname = NULL,		-- user's local user name
	@remotename		sysname = NULL		-- user's remote name
as
	declare @sid varbinary(85)

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

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


	-- CHECK FOR INVALID PARAMETER SYNTAX 
	if @remoteserver is null OR (@loginame is null and @remotename is not null)
	begin
		raiserror(15600,-1,-1,'sys.sp_dropremotelogin')
		return (1)
	end

	BEGIN TRAN

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

	-- VALIDATE/LOCK @loginame 
	if @loginame is not null
	begin
		-- share-lock the local login
		EXEC %%LocalLogin ( Name = @loginame ) . Lock ( Exclusive = 0 )
		IF @@ERROR = 0
			select @sid = sid from sys.server_principals
				where name = @loginame and type = 'S'		-- cannot map to NT login
		if @sid is null
		begin
			ROLLBACK TRAN
			raiserror(15007,-1,-1,@loginame)
			return (1)
		end
	end

	-- CHECK IF REQUESTED MAPPING ACTUALLY EXISTS 
	IF NOT EXISTS (SELECT * FROM master.dbo.sysremotelogins WHERE
			remoteserverid IN (SELECT srvid FROM master.dbo.sysservers WHERE srvname = @remoteserver)
			AND ((@sid IS NULL and sid IS NULL) or sid = @sid)
			AND ((@remotename IS NULL and remoteusername IS NULL) or remoteusername = @remotename) )
	BEGIN
		ROLLBACK TRAN
		raiserror(15185,-1,-1,@remotename,@loginame,@remoteserver)
		return (1)
	END

	-- DROP REMOTE LOGIN 
	EXEC %%LinkedServer(Name=@remoteserver).RemoveRemoteLogin( RemoteName = @remotename )

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

 
Last revision 2008RTM
See also

  sp_dropdistpublisher (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