Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSprocesslogshipmonitorlink

  No additional text.


Syntax
create procedure sys.sp_MSprocesslogshipmonitorlink
(
    @mode tinyint -- 1 = create, 2 = drop
    ,@monitor_server sysname
    ,@monitor_server_security_mode bit -- 0 = standard, 1 = integrated
    ,@monitor_server_login sysname = NULL
    ,@monitor_server_password sysname = NULL
)
as
begin
    set nocount on
    declare @retcode int
                ,@linkname sysname
                ,@localproxy sysname
                ,@cmd nvarchar(4000)

    
    -- validate @mode
    
    if (@mode not in (1,2))
    begin
        raiserror(21055, 16, -1, '@mode','sp_MSprocesslogshipmonitorlink')
        return 1
    end
    
    -- login and password cannot be null for security_mode 0 during creation
    
    if (@mode = 1 and @monitor_server_security_mode = 0 and (@monitor_server_login is null or @monitor_server_password is null))
    begin
        raiserror(21055, 16, -1, '@monitor_server_login, @monitor_server_password', '@monitor_server_security_mode = 0')
        return 1
    end
    
    -- we will use a deterministic name for the link
    
    select @monitor_server = upper(@monitor_server)
             ,@localproxy = SUSER_SNAME(0x01)
    select @linkname = upper(sys.fn_MSgetlogshippingmoniterlinkname(@monitor_server))
    
    -- drop it if it exists
    
    if exists (select * from master.sys.servers
            where upper(name) = @linkname and upper(data_source) = @monitor_server)
    begin
        exec @retcode = sp_dropserver @server = @linkname, @droplogins = 'droplogins'
        if @@error <> 0 or @retcode <> 0
            return 1
    end
    
    -- if we are dropping - we are done
    
    if (@mode = 2)
        return 0
    
    -- create the linked server entry
    
    exec @retcode = sp_addlinkedserver @server = @linkname, @srvproduct = 'SQL Server'
    if @@error != 0 or @retcode != 0
        return 1
    
    -- Set the data source name
    
    exec @retcode = sys.sp_setnetname  @linkname, @monitor_server
    if @@error != 0 or @retcode != 0
        return 1
    
    -- set the properties for the linked server so that it can be used by logshipping
    
    exec @retcode = sys.sp_serveroption @linkname, 'data access', 'true'
    if @@error != 0 or @retcode != 0
        return 1
    exec @retcode = sys.sp_serveroption @linkname, 'rpc', 'true'
    if @@error != 0 or @retcode != 0
        return 1
    exec @retcode = sys.sp_serveroption @linkname, 'rpc out', 'true'
    if @@error != 0 or @retcode != 0
        return 1
    exec @retcode = sys.sp_serveroption @linkname, 'system', 'true'
    if @@error != 0 or @retcode != 0
        return 1
    
    -- prepare monitor credential
    
    if (@monitor_server_security_mode = 0)
    begin
        
        -- now add the proxy credential
        
        exec @retcode = sp_addlinkedsrvlogin @rmtsrvname = @linkname
                                                    ,@useself = 'false' -- we will use specific remote login
                                                    ,@locallogin = @localproxy -- only this login can use it
                                                    ,@rmtuser = @monitor_server_login
                                                    ,@rmtpassword = @monitor_server_password
        if @@error != 0 or @retcode != 0
            return 1
        
        -- remove default login mapping
        
        exec sp_droplinkedsrvlogin @rmtsrvname = @linkname, @locallogin = NULL
    end
    else
    begin
        exec @retcode = sp_addlinkedsrvlogin @rmtsrvname = @linkname
                                                    ,@useself = 'true' -- we will use self credentials
        if @@error != 0 or @retcode != 0
            return 1
    end
    
    -- all done
    
    return 0
end

 
Last revision 2008RTM
See also

  sp_add_log_shipping_primary_database (Procedure)
sp_add_log_shipping_secondary_primary (Procedure)
sp_change_log_shipping_primary_database (Procedure)
sp_change_log_shipping_secondary_primary (Procedure)
sp_delete_log_shipping_primary_database (Procedure)
sp_delete_log_shipping_secondary_primary (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