Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_change_log_shipping_secondary_primary

  No additional text.


Syntax
create procedure sys.sp_change_log_shipping_secondary_primary
(
    @primary_server sysname -- cannot be NULL
    ,@primary_database sysname -- cannot be NULL
    ,@backup_source_directory nvarchar(500) = NULL
    ,@backup_destination_directory nvarchar(500) = NULL
    ,@file_retention_period int = NULL
    ,@monitor_server_security_mode bit = NULL
    ,@monitor_server_login sysname = NULL
    ,@monitor_server_password sysname = NULL
)
as
begin
    set nocount on
    declare @retcode int
                ,@secondary_id uniqueidentifier
                ,@monitor_server sysname
                ,@existing_security_mode int

    
    -- security check
    
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    
    -- must be invoked from master db
    
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    
    -- Does the primary exist
    
    select @secondary_id = secondary_id
            ,@monitor_server = monitor_server
            ,@existing_security_mode = monitor_server_security_mode
    from msdb.dbo.log_shipping_secondary
    where primary_server = upper(@primary_server)
        and primary_database = @primary_database
    if (@secondary_id is null)
    begin
        raiserror(32023, 16, 1, @primary_server, @primary_database)
        return 1
    end
    
    -- refresh monitor link if the monitor credentials are have been specified
    
    if (upper(@monitor_server) != upper(@@servername)
        and (@monitor_server_security_mode is not null
                or @monitor_server_login is not null
                or @monitor_server_password is not null))
    begin
        
        -- check if only login credentials have changed
        
        if (@monitor_server_security_mode is not null)
            select @existing_security_mode = @monitor_server_security_mode
        
        -- create link for monitor server
        
        exec @retcode = msdb.sys.sp_MSprocesslogshipmonitorlink @mode = 1
                                        ,@monitor_server = @monitor_server
                                        ,@monitor_server_security_mode = @existing_security_mode
                                        ,@monitor_server_login = @monitor_server_login
                                        ,@monitor_server_password = @monitor_server_password
        if (@retcode != 0 or @@error != 0)
            return 1
    end
    
    -- start transaction
    
    begin tran sp_change_ls_sd
    save tran sp_change_ls_sd
    
    -- update log_shipping_secondary
    
    update msdb.dbo.log_shipping_secondary
    set backup_source_directory = case when (@backup_source_directory is null) then backup_source_directory else @backup_source_directory end
         ,backup_destination_directory = case when (@backup_destination_directory is null) then backup_destination_directory else @backup_destination_directory end
         ,monitor_server_security_mode = case when (@monitor_server_security_mode is null) then monitor_server_security_mode else @monitor_server_security_mode end
         ,file_retention_period = case when (@file_retention_period is null) then file_retention_period else @file_retention_period end
    where secondary_id = @secondary_id
    if (@@error != 0)
        goto UNDO
    
    -- commit
    
    commit tran
    
    -- all done
    
    return 0

UNDO:
    rollback tran sp_change_ls_sd
    commit tran
    return 1
end

 
Last revision 2008RTM
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