Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSrestore_sub

  No additional text.


Syntax
create procedure sys.sp_MSrestore_sub
(
    @subscriber_security_mode 	int,
    @subscriber_login           sysname,
    @subscriber_password        nvarchar(524),
    @distributor_security_mode	int,
	@distributor_login			sysname,
	@distributor_password		sysname,
	@publisher_security_mode	int,
	@publisher_login			sysname,
	@publisher_password			sysname,
	@job_login					nvarchar(257),
	@job_password				sysname,
	@db_master_key_password		nvarchar(524) = NULL
)
AS

    SET NOCOUNT ON

	-- NOTE on PASSWORD parameters:
	
	-- It should be noted that we only allow you to specify
	-- one distributor/publisher security mode, login and
	-- password even though it is possible that the subscriber
	-- database being attached had more than one subscription
	-- that pointed to different dists/pubs. We made the decision
	-- to add these parameters anyway since it would ease the
	-- pain of 98% of our users who only have one subscription
	-- being copied.
	
    /*
    ** Declarations.
    */
    declare @retcode int,
    		@command nvarchar(4000)

    -- Initialization
    select @retcode = 0

	-- if master db key password was provided then we will open it
	IF @db_master_key_password IS NOT NULL
	BEGIN
		SELECT @command = 'OPEN MASTER KEY DECRYPTION BY PASSWORD = ''' + replace(@db_master_key_password, '''', '''''') + ''''
		EXEC(@command )
		IF @@ERROR <> 0
		BEGIN
			SELECT @retcode = 1
			GOTO Cleanup
		END

		-- create the keys/certificates required by repl for encryption
		-- we will do this here just in case the symmetric keys were dropped
		EXEC @retcode = sys.sp_MSaddreplsymmetrickey
		IF @@ERROR <> 0 OR @retcode <> 0
		BEGIN
			SELECT @retcode = 1
			GOTO Cleanup
		END
	END
	ELSE
	BEGIN
		-- if the master key was not provided then we should check to see if
		-- we can open the symetric key. sp_MSreplopensymmetrickey works in
		-- the following manner:
		--  1) Master key does not exist it retruns 0
		--  2) Master key exists, it will attempt to create or open
		--     the symmetric key and will fail if master key is not open
		
		-- Note that even though we are attempting to open the symetric keys
		-- we will not use it to decrypt any replication passwords since on
		-- copy we wipe out all passwords. here we are just ensuring that if
		-- a master key exists we will be able to access it and use it durring
		-- the encryption of new passwords.
		EXEC @retcode = sys.sp_MSreplopensymmetrickey
		IF @@ERROR <> 0 OR @retcode <> 0
		BEGIN
			SELECT @retcode = 1
			GOTO Cleanup
		END

		-- we should close this immediately since we were just
		-- testing to see if the  master key was available...
		EXEC @retcode = sys.sp_MSreplclosesymmetrickey
		IF @@ERROR <> 0 OR @retcode <> 0
		BEGIN
			SELECT @retcode = 1
			GOTO Cleanup
		END
	END
	
    if object_id('MSreplication_subscriptions') is not NULL
    begin
        exec @retcode = sys.sp_MSrestore_sub_tran
            @subscriber_security_mode = @subscriber_security_mode,
            @subscriber_login = @subscriber_login,
            @subscriber_password = @subscriber_password,
            @distributor_security_mode = @distributor_security_mode,
            @distributor_login = @distributor_login,
            @distributor_password = @distributor_password,
            @job_login = @job_login,
            @job_password = @job_password
        if @@error <> 0 or @retcode <> 0
        begin
            select @retcode = 1
            goto Cleanup
        end
    end
    if object_id('sysmergesubscriptions') is not NULL
    begin
        exec @retcode = sys.sp_MSrestore_sub_merge
            @subscriber_security_mode = @subscriber_security_mode,
            @subscriber_login = @subscriber_login,
            @subscriber_password = @subscriber_password,
            @distributor_security_mode = @distributor_security_mode,
            @distributor_login = @distributor_login,
            @distributor_password = @distributor_password,
            @publisher_security_mode = @publisher_security_mode,
            @publisher_login = @publisher_login,
            @publisher_password = @publisher_password,
            @job_login = @job_login,
            @job_password = @job_password
        if @@error <> 0 or @retcode <> 0
        begin
            select @retcode = 1
            goto Cleanup
        end
    end

Cleanup:
    if object_id('MSreplication_restore_stage') is not NULL
        drop table MSreplication_restore_stage

    return    @retcode

 
Last revision 2008RTM
See also

  sp_attachsubscription (Procedure)
sp_MSrestore_sub_merge (Procedure)
sp_MSrestore_sub_tran (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