Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_dropreplsymmetrickey

  No additional text.


Syntax

-- Name:
--	sp_dropreplsymmetrickey

-- Description:
--	This procedure drops the following:
--		Database symmetric key based on a password seed
--		Database level certificate with associated asymmetric public/private keys
--		Database level scoped replication symetric key used for encrypting

-- Parameters:
--	See the procedure definition.

-- Returns:
--	0 - On success
--	1 - On Failure

-- Result:
--	None

-- Security:
--	Must be DBO to execute.

CREATE PROCEDURE sys.sp_dropreplsymmetrickey
(
	@check_replication bit = 0,
	@throw_error bit = 1
)
AS
BEGIN
	DECLARE @error_number 	int,
			@error_severity int,
			@error_state 	int


	-- security check
    IF IS_MEMBER('db_owner') != 1
	BEGIN
		RAISERROR(21050, 14, -1)
		RETURN 1
    END

	IF @check_replication = 1
	BEGIN
		-- if requested we want to ensure that the current database is not :
		--		1) tran published
		--		2) tran subscriber
		--		3) merge published
		--		4) merge subscriber
	    IF sys.fn_MSrepl_istranpublished(DB_NAME(), 1) = 1
			OR (OBJECT_ID(N'MSreplication_subscriptions', N'U') IS NOT NULL
				OR OBJECT_ID(N'MSsubscription_properties', N'U') IS NOT NULL)
			OR sys.fn_MSrepl_ismergepublished(DB_NAME()) = 1
			OR (OBJECT_ID(N'MSmerge_replinfo', N'U') IS NOT NULL
				OR OBJECT_ID(N'sysmergesubscriptions', N'U') IS NOT NULL
				OR OBJECT_ID(N'sysmergepublications', N'U') IS NOT NULL
				OR OBJECT_ID(N'MSsubscription_properties', N'U') IS NOT NULL)
		BEGIN
			RETURN 0
		END
	END
	
	BEGIN TRY
		DROP SYMMETRIC KEY SQLSERVER_REPLICATION
	END TRY
	BEGIN CATCH
		-- we eat the following error:
		--  Msg 15151, Level 16, State 1, Line 1
		--  Cannot drop the symmetric key 'SQLSERVER_REPLICATION', because it does not exist or you do not have permission.
		IF @@ERROR != 15151
		BEGIN
			IF @throw_error = 1
			BEGIN
				SELECT @error_number = ERROR_NUMBER(),
						@error_severity = ERROR_SEVERITY(),
						@error_state = ERROR_STATE()

				RAISERROR(@error_number, @error_severity, @error_state)
			END
			
			RETURN 1
		END
	END CATCH

	BEGIN TRY
		DROP CERTIFICATE SQLSERVER_REPLICATION
	END TRY
	BEGIN CATCH
		-- we eat the following error:
		--  Msg 15151, Level 16, State 1, Line 1
		--  Cannot drop the certificate 'SQLSERVER_REPLICATION', because it does not exist or you do not have permission.
		IF @@ERROR != 15151
		BEGIN
			IF @throw_error = 1
			BEGIN
				SELECT @error_number = ERROR_NUMBER(),
						@error_severity = ERROR_SEVERITY(),
						@error_state = ERROR_STATE()

				RAISERROR(@error_number, @error_severity, @error_state)
			END
			
			RETURN 1
		END
	END CATCH
	
	RETURN 0
END

 
Last revision 2008RTM
See also

  sp_dropmergepullsubscription (Procedure)
sp_removedbreplication (Procedure)
sp_replicationdboption (Procedure)
sp_subscription_cleanup (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