Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSispulldistributionjobnamegenerated

  No additional text.


Syntax

-- Name: sp_MSispulldistributionjobnamegenerated

-- Descriptions: This procedure checks whether a given job id corresponds to
--               a pull distribution agent job with a name generated by replication.
--               If so, a return value of zero will be returned, otherwise
--               a value of one will be returned to the caller.

-- Notes: 1) For this procedure to be effective, it must match the current
--           pull distribution agent name generation algorithm. Note that the
--           algorithm used for matching auto-generated job name is not
--           exact. (See sp_addpullsubscription_agent replsys.sql)
--        2) This procedure is supposed to be executed at the subscriber
--           database. The subscriber server name and subscriber database
--           name for contructing the generated job name are obtained via
--           the serverproperty('ServerName') and the db_name() functions.

-- Parameters: @publisher     sysname
--             @publisher_db  sysname
--             @publication   sysname (This can be null for shared agent)
--             @job_id        uniqueidentifier

-- Returns: 0 - If the specified jobid corresponds to a snapshot job with
--              a generated name.
--          1 - Otherwise

-- Security: This is an internal system procedure.

create procedure sys.sp_MSispulldistributionjobnamegenerated (
    @publisher     sysname,
    @publisher_db  sysname,
    @publication   sysname,
    @job_id        uniqueidentifier
    )
as
begin
    set nocount on

    declare @generated_job_name nvarchar(4000)
    declare @generated_job_name_length int
    declare @job_name sysname

    select @job_name = null
    select @job_name = name
      from msdb.dbo.sysjobs_view
     where job_id = @job_id

    if @job_name is null
    begin
        goto MISMATCH
    end

    -- First of all, make sure that the job is indeed a distribution agent
    -- job (there should be a step with Distribution as the subsystem in the
    -- job)
    if not exists (select *
                     from msdb.dbo.sysjobsteps
                    where job_id = @job_id
                      and upper(subsystem collate SQL_Latin1_General_CP1_CS_AS) = N'DISTRIBUTION')
    begin
        goto MISMATCH
    end

    -- Pull distribution agent names are always generated with a guid
    select @generated_job_name = left(@publisher, 18) + N'-'
                               + left(isnull(@publisher_db,N''), 18) + N'-'
                               + left(@publication, 18) + N'-'
                               + left(convert(nvarchar(4000),serverproperty('ServerName')), 18) + N'-'
                               + left(db_name(), 18) + N'-'

    select @generated_job_name_length = len(@generated_job_name)

    -- Try matching the prefix of the job name
    if upper(left(@job_name, @generated_job_name_length)) = upper(@generated_job_name)
    begin
        -- Checks if the tail end of the job name matches a hexadecimal guid
        -- with embedded dashes
        if upper(right(@job_name, len(@job_name) - @generated_job_name_length) collate SQL_Latin1_General_CP1_CS_AS)
            like N'[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]-[0-9A-F][0-9A-F][0-9A-F][0-9A-F]-[0-9A-F][0-9A-F][0-9A-F][0-9A-F]-[0-9A-F][0-9A-F][0-9A-F][0-9A-F]-[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]
[0-9A-F][0-9A-F][0-9A-F]'
        begin
            return 0
        end
        else
        begin
            goto MISMATCH
        end
    end

MISMATCH:
    if @job_name is not null
    begin
        raiserror(21695, -1, -1, @job_name)
    end
    return 1
end

 
Last revision 2008RTM
See also

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