Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSrepl_testadminconnection

  No additional text.


Syntax

CREATE PROCEDURE sys.sp_MSrepl_testadminconnection
(
    @distributor        sysname,
    @password           sysname = null
)
AS
BEGIN
    DECLARE @retcode      int
    DECLARE @linkedsvr    sysname
    DECLARE @login        sysname

    -------- security check, db_owner
    EXEC @retcode = dbo.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RETURN(1)
    END

    SELECT @linkedsvr    = CONVERT(sysname, newid()),
           @login        = N'distributor_admin'

    -- Verify @distributor
    IF @distributor IS NULL OR @distributor = N''
    BEGIN
        RAISERROR (14043, 16, -1, '@distributor', 'sp_MSrepl_testadminconnection')
        RETURN (1)
    END

    EXEC @retcode = sys.sp_validname @distributor

    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)

    -- Validate @password
    IF @password IS NULL OR @password = N''
    BEGIN
        RAISERROR(14043, 16, -1, N'@password', 'sp_MSrepl_testadminconnection')
        RETURN (1)
    END

    -- Add temporary linked server entry to test distributor_admin credentials
    EXEC @retcode = sys.sp_addserver  @linkedsvr
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        RETURN (1)
    END

    -- Mark system link
    EXECUTE @retcode = sys.sp_serveroption  @linkedsvr, 'system', 'true'
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        GOTO UNDO
    END

    -- Set net name of test link to distributor server name
    EXECUTE @retcode = sys.sp_setnetname  @linkedsvr, @distributor
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        GOTO UNDO
    END

    exec @retcode = sys.sp_addlinkedsrvlogin    @rmtsrvname  = @linkedsvr,
                                                @useself     = 'false',
                                                @locallogin  = NULL,
                                                @rmtuser     = @login,
                                                @rmtpassword = @password
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        GOTO UNDO
    END

    -- Test connection
    BEGIN TRY
        DECLARE @distproc nvarchar(max)
        DECLARE @result int

        SELECT @distproc = QUOTENAME(RTRIM(@linkedsvr)) + '.master.sys.sp_executesql'
        EXEC @retcode = @distproc N'SELECT @p1=@@microsoftversion', N'@p1 int OUTPUT', @result OUTPUT
    END TRY
    BEGIN CATCH
        RAISERROR(21670, 16, -1, @distributor)
        SET @retcode = 1
    END CATCH

    -- Cleanup
UNDO:
    IF EXISTS (SELECT * FROM sys.servers WHERE name = @linkedsvr)
    BEGIN
        EXEC sys.sp_dropserver @linkedsvr, 'droplogins'
    END

    RETURN (@retcode)
END

 
Last revision 2008RTM
See also

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